package com.xbongbong.paas.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.constant.TimeConstant;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.elasticsearch.pojo.dto.SearchDataInConditionDTO;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.EsAliasEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.PlatFormEnum;
import com.xbongbong.paas.enums.RangeScreenTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkInfoPojo;
import com.xbongbong.paas.field.LinkedAttrPoJo;
import com.xbongbong.paas.help.FormDataListSearchHelp;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.pojo.ButtonPojo;
import com.xbongbong.paas.pojo.ItemDataPoJo;
import com.xbongbong.paas.pojo.ScreenListPojo;
import com.xbongbong.paas.pojo.dto.ExplainScreenListDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.RelationClueScreenListDTO;
import com.xbongbong.paas.pojo.dto.Screen4DistributorDTO;
import com.xbongbong.paas.pojo.dto.ScreenAddDTO;
import com.xbongbong.paas.pojo.dto.ScreenListDTO;
import com.xbongbong.paas.pojo.dto.UserConfigAddDTO;
import com.xbongbong.paas.pojo.vo.ExplainScreenListVO;
import com.xbongbong.paas.pojo.vo.ScreenAddVO;
import com.xbongbong.paas.pojo.vo.ScreenListVO;
import com.xbongbong.paas.pojo.vo.SearchDataInConditionVO;
import com.xbongbong.paas.pojo.vo.UserConfigAddVO;
import com.xbongbong.paas.redis.PaasRedisHelper;
import com.xbongbong.paas.redis.RedisPrefixConstant;
import com.xbongbong.paas.service.PaasFormExplainService;
import com.xbongbong.paas.service.ProFormDataService;
import com.xbongbong.paas.service.ScreenService;
import com.xbongbong.paas.service.UserConfigService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.parent.explain.FormDataAddFormExplainHandlerName;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.constant.CommonConstant;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.constant.RangeScreenConstant;
import com.xbongbong.pro.constant.SymbolConstant;
import com.xbongbong.pro.domain.entity.StockDateFilterEntity;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.TimeTypeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.statistic.enums.SystemCodeEnum;
import com.xbongbong.pro.weblist.pojo.SpecialListFieldPojo;
import com.xbongbong.saas.constant.MultiUnitConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.domain.entity.WorkOrderExplainEntity;
import com.xbongbong.saas.domain.entity.ext.WorkOrderExplainEntityExt;
import com.xbongbong.saas.enums.BirthdayFilterEnum;
import com.xbongbong.saas.enums.CustomerStatementEnum;
import com.xbongbong.saas.enums.DefaultScreenEnum;
import com.xbongbong.saas.enums.ListBusinessTypeEnum;
import com.xbongbong.saas.enums.ListGroupEnum;
import com.xbongbong.saas.enums.OperateTypeEnum;
import com.xbongbong.saas.enums.PaymentSourceTypeEnum;
import com.xbongbong.saas.enums.SelectProductEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.StockFilterTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.*;
import com.xbongbong.saas.enums.dictionary.ArchivedEnum;
import com.xbongbong.saas.enums.dictionary.ClueStatusEnum;
import com.xbongbong.saas.enums.product.CostAdjustProductEnum;
import com.xbongbong.saas.help.MarketManagementBusinessHelp;
import com.xbongbong.saas.help.RelativeProductHelp;
import com.xbongbong.saas.help.ScoreRuleHelp;
import com.xbongbong.saas.help.SearchFilterHelp;
import com.xbongbong.saas.model.ScoreRangeModel;
import com.xbongbong.saas.model.StockDateFilterModel;
import com.xbongbong.saas.model.WorkOrderExplainModel;
import com.xbongbong.saas.service.ScoreRangeService;
import com.xbongbong.sys.domain.entity.UserConfigEntity;
import com.xbongbong.sys.enums.UserConfigEnum;
import com.xbongbong.sys.model.UserConfigModel;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author: wufeng
 * @date: 2018/9/11 10:21
 * @desrcption:
 */
@Service("screenService")
public class ScreenServiceImpl implements ScreenService {

    private static final Logger LOG = LoggerFactory.getLogger(ScreenServiceImpl.class);

    @Resource
    private PaasRedisHelper paasRedisHelper;
    @Resource
    private PaasFormExplainService paasFormExplainService;
    @Resource
    private UserConfigService userConfigService;
    @Resource
    private UserConfigModel userConfigModel;
    @Resource
    private PaasFormExplainModel paasFormExplainModel;
    @Resource
    private WorkOrderExplainModel workOrderExplainModel;
    @Resource
    private RelativeProductHelp relativeProductHelp;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private FormDataAddFormExplainHandlerName formDataAddFormExplainHandlerName;
    @Resource
    private StockDateFilterModel stockDateFilterModel;
    @Resource
    private FormDataListSearchHelp formDataListSearchHelp;
    @Resource
    private SearchFilterHelp searchFilterHelp;
    @Resource
    private ProFormDataService proFormDataService;
    @Resource
    private ScoreRangeService scoreRangeService;
    @Resource
    private ScoreRangeModel scoreRangeModel;
    @Resource
    private MarketManagementBusinessHelp marketManagementBusinessHelp;
    @Resource
    private ScoreRuleHelp scoreRuleHelp;

    @Override
    public ScreenAddVO add(ScreenAddDTO screenAddDTO) throws XbbException {
        ScreenAddVO screenAddVO = new ScreenAddVO();
        try {
            String key = getRrdisKey(screenAddDTO.getSubBusinessType(), screenAddDTO.getCorpid(), screenAddDTO.getAppId(), screenAddDTO.getFormId(), screenAddDTO.getUserId());
            String screens = "";
            if (screenAddDTO.getScreenList() != null && !screenAddDTO.getScreenList().isEmpty()) {
                for (String searchItem: screenAddDTO.getScreenList()) {
                    if(StringUtil.isEmpty(screens)){
                        screens = searchItem;
                    }else{
                        screens += "," + searchItem;
                    }
                }
            }
            // 保存到数据库中
            UserConfigAddDTO userConfigAddDTO = new UserConfigAddDTO();
            BeanUtil.copyProperties(screenAddDTO, userConfigAddDTO);
            String redisPrefix = getRrdisPrefix(screenAddDTO.getBusinessType(),screenAddDTO.getSubBusinessType());
            // 31135 【库存查询】批次保质期查询列表常用筛选设置在刷新页面后就无效了
            if (Objects.equals(screenAddDTO.getBusinessType(), XbbRefTypeEnum.PRODUCT.getCode()) && Objects.equals(screenAddDTO.getSubBusinessType(), XbbRefTypeEnum.STOCK_SEARCH.getCode())) {
                if (Objects.equals(screenAddDTO.getFormId(), ListGroupEnum.GUARANTEE_SEARCH.getCode().longValue())) {
                    redisPrefix = UserConfigEnum.FORM_COMMON_FILTER.getAlias();
                }
            }
            String configAlias = redisPrefix + "_" +key;
            userConfigAddDTO.setConfigName(UserConfigEnum.FORM_COMMON_FILTER.getName());
            userConfigAddDTO.setConfigAlias(configAlias);
            userConfigAddDTO.setConfigValue(screens);
            UserConfigAddVO userConfigAddVO = userConfigService.save(userConfigAddDTO);
            screenAddVO.setUserConfigId(userConfigAddVO.getUserConfigId());
            paasRedisHelper.setValue(redisPrefix, key, screens, TimeConstant.SEARCH_EFFECTIVE_TIME);
        } catch (Exception e) {
            LOG.error("redis设置常用筛选项出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return screenAddVO;
    }

    @Override
    public ScreenListVO list(ScreenListDTO screenListDTO) throws XbbException {
        ScreenListVO screenListVO = new ScreenListVO();
        try {
            String key = getRrdisKey(screenListDTO.getSubBusinessType(),screenListDTO.getCorpid(),screenListDTO.getAppId(),screenListDTO.getFormId(),screenListDTO.getUserId());
            ExplainScreenListDTO explainScreenListDTO = new ExplainScreenListDTO();
            BeanUtil.copyProperties(screenListDTO, explainScreenListDTO);
            ExplainScreenListVO explainScreenListVO = paasFormExplainService.screenList(explainScreenListDTO);
            JSONArray explainJsonArray = new JSONArray();
            JSONArray screenJsonArray = new JSONArray();
            screenListVO.setScreen(new String[]{});
            String value = "";
            // 待系列列表筛选固定特殊处理
            if (Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.WAIT_OUTSTOCK.getCode())
                    || Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.WAIT_PURCHASE.getCode())
                    || Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode())
                    || Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.SMART_REPLENISHMENT.getCode())) {
                if (Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.SMART_REPLENISHMENT.getCode())){
                    value = "array_1,num_8";
                } else if (Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.PURCHASE.getCode()) || Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.CONTRACT.getCode())){
                    value = "array_2";
                } else if (Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.PRODUCT.getCode())) {
                    if (Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.WAIT_OUTSTOCK.getCode())) {
                        value = "array_2,array_4";
                    }else {
                        value = "array_1,array_2";
                    }
                }
                explainJsonArray = explainScreenListVO.getFormExplainList();
                String redisPrefix = getRrdisPrefix(screenListDTO.getBusinessType(),screenListDTO.getSubBusinessType());
                String redisValue = paasRedisHelper.getValue(redisPrefix, key);
                if (Objects.equals(PlatFormEnum.DINGTALK.getValue(), screenListDTO.getPlatform())){
                    if (redisValue != null) {
                        value = redisValue;
                    }
                }
            }else if(explainScreenListVO  != null && explainScreenListVO .getFormExplainList().size() > 0) {
                String redisPrefix = getRrdisPrefix(screenListDTO.getBusinessType(),screenListDTO.getSubBusinessType());
                if (Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.PRODUCT.getCode()) && Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.STOCK_SEARCH.getCode())) {
                    if (Objects.equals(explainScreenListDTO.getFormId(), ListGroupEnum.GUARANTEE_SEARCH.getCode().longValue())) {
                        redisPrefix = UserConfigEnum.FORM_COMMON_FILTER.getAlias();
                        screenListDTO.setSubBusinessType(XbbRefTypeEnum.GUARANTEE_SEARCH.getCode());
                    }
                }
                value = paasRedisHelper.getValue(redisPrefix, key);
                if (StringUtil.isEmpty(value)) {
                    String configAlias = redisPrefix + "_" +key;
                    if (Objects.equals(screenListDTO.getBusinessType(),XbbRefTypeEnum.ORI_STOCK.getCode())){
                        screenListDTO.setUserId("0");
                        screenListDTO.setCorpid("0");
                    }
                    UserConfigEntity userConfigEntity = null;
                    if (!(Objects.equals(XbbRefTypeEnum.SUPPLIER.getCode(), screenListDTO.getBusinessType()) && Objects.equals(XbbRefTypeEnum.SUPPLIER_PRODUCT.getCode(), screenListDTO.getSubBusinessType()))) {
                        userConfigEntity = userConfigModel.getByUserId(screenListDTO.getUserId(), screenListDTO.getCorpid(), configAlias);
                    }
                    if(userConfigEntity != null) {
                        value = userConfigEntity.getConfigValue();
                    }else if (!Objects.isNull(screenListDTO.getBusinessType()) && !Objects.equals(screenListDTO.getBusinessType(), 0)){
                         value = DefaultScreenEnum.getDefaultValue(screenListDTO.getBusinessType(),screenListDTO.getSubBusinessType(),screenListDTO.getPlatform());
                    }else{
                        explainJsonArray = explainScreenListVO.getFormExplainList();
                    }
                }
                if (Objects.equals(SaasMarkEnum.SAAS.getCode(), explainScreenListVO.getSaasMark())) {
                    Map<String, FieldAttrEntity> explainMap = ExplainUtil.getExplainMap(JSONArray.toJSONString(explainScreenListVO.getFormExplainList()), null);
                    //是否有评分筛选(满足(1)属于支持评分的业务(2)套餐不是标准版(3)表单下有启用的评分规则)
                    Boolean haveScoreScreen = XbbRefTypeEnum.checkScoreBusinessType(screenListDTO.getBusinessType()) && !(marketManagementBusinessHelp.isStandardWithFeeType(screenListDTO.getCorpid())) && scoreRuleHelp.haveEnabledScoreRule(screenListDTO.getCorpid(),screenListDTO.getFormId());
                    for(Map.Entry<String,FieldAttrEntity> item: explainMap.entrySet()) {
                        FieldAttrEntity fieldAttrEntity = item.getValue();
                        if (Objects.equals(LocaleContextHolder.getLocale().getLanguage(), I18nStringConstant.ENGLISH_LANGUAGE)) {
                            // 切成英文的字段展示
                            String attrName = fieldAttrEntity.getAttrName();
                            String attrNameEn = fieldAttrEntity.getAttrNameEn();
                            fieldAttrEntity.setAttrName(attrName);
                            fieldAttrEntity.setAttrNameEn(attrNameEn);
                        }
                        if (ShowTypeEnum.listShow(fieldAttrEntity.getShowType())){
                            if (Objects.equals(screenListDTO.getBusinessType(),XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()) && Objects.equals(fieldAttrEntity.getAttr(), CustomerManagementEnum.BACK_PUBLIC_DATE.getAttr())) {
                                formatBackPublicDate(explainJsonArray,fieldAttrEntity, screenListDTO.getSubBusinessType());
                            } else if (Objects.equals(screenListDTO.getSubBusinessType(),XbbRefTypeEnum.CUSTOMER_PUBLIC.getCode()) && Objects.equals(fieldAttrEntity.getAttr(), CustomerManagementEnum.OWNER_ID.getAttr())){
                                if (Objects.equals(LocaleContextHolder.getLocale().getLanguage(), I18nStringConstant.ENGLISH_LANGUAGE)) {
                                    fieldAttrEntity.setAttrNameEn(I18nMessageUtil.getMessage(I18nStringConstant.PRE_OWNER_ID));
                                } else {
                                    fieldAttrEntity.setAttrName(I18nMessageUtil.getMessage(I18nStringConstant.PRE_OWNER_ID));
                                }
                                explainJsonArray.add(fieldAttrEntity);
                            } else if (Objects.equals(screenListDTO.getBusinessType(),XbbRefTypeEnum.CLUE.getCode()) && Objects.equals(fieldAttrEntity.getAttr(), ClueEnum.BACK_PUBLIC_DATE.getAttr())) {
                                formatBackPublicDate(explainJsonArray,fieldAttrEntity, screenListDTO.getSubBusinessType());
                            } else if (Objects.equals(screenListDTO.getSubBusinessType(),XbbRefTypeEnum.CLUE_PUBLIC.getCode()) && Objects.equals(fieldAttrEntity.getAttr(), ClueEnum.OWNER_ID.getAttr())){
                                if (Objects.equals(LocaleContextHolder.getLocale().getLanguage(), I18nStringConstant.ENGLISH_LANGUAGE)) {
                                    fieldAttrEntity.setAttrNameEn(I18nMessageUtil.getMessage(I18nStringConstant.PRE_OWNER_ID));
                                } else {
                                    fieldAttrEntity.setAttrName(I18nMessageUtil.getMessage(I18nStringConstant.PRE_OWNER_ID));
                                }
                                explainJsonArray.add(fieldAttrEntity);
                            }else if (Objects.equals(fieldAttrEntity.getFieldType(),FieldTypeEnum.SELECT_PRODUCT.getType())){
                                //列表筛选选择产品移除subForm,防止前端解析成子表单
//                                fieldAttrEntity.setSubForm(null);
                                explainJsonArray.add(fieldAttrEntity);
                            }else if (Objects.equals(screenListDTO.getSubBusinessType(),XbbRefTypeEnum.WAIT_PURCHASE.getCode()) || Objects.equals(screenListDTO.getSubBusinessType(),XbbRefTypeEnum.WAIT_PRODUCE.getCode())){
                                if (!Objects.equals(fieldAttrEntity.getAttr(),ProductEnum.STOCK.getAttr())){
                                    explainJsonArray.add(fieldAttrEntity);
                                }
                            }else if (Objects.equals(screenListDTO.getBusinessType(),XbbRefTypeEnum.PRODUCT.getCode()) && Objects.equals(screenListDTO.getSubBusinessType(),XbbRefTypeEnum.PRODUCT.getCode())) {
                                //保证不影响到待采购生产，库存查询
                                if (Objects.equals(fieldAttrEntity.getAttr(),ProductEnum.PRICE.getAttr()) || Objects.equals(fieldAttrEntity.getAttr(),ProductEnum.COST.getAttr()) || Objects.equals(fieldAttrEntity.getAttr(),ProductEnum.STOCK.getAttr())){
                                    continue;
                                }else {
                                    explainJsonArray.add(fieldAttrEntity);
                                }
                            } else {
                                if (Objects.equals(fieldAttrEntity.getAttr(), SelectProductEnum.PRODUCT.getAttr()) && Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.ORI_STOCK.getCode())){
                                    fieldAttrEntity.setFieldType(FieldTypeEnum.TEXTAREA.getType());
                                } else if (Objects.equals(fieldAttrEntity.getAttr(), SelectProductEnum.BATCH.getAttr()) && Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.ORI_STOCK.getCode())){
                                    fieldAttrEntity.setFieldType(FieldTypeEnum.TEXTAREA.getType());
                                } else if (Objects.equals(fieldAttrEntity.getAttr(), SelectProductEnum.NUM.getAttr()) && Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.ORI_STOCK.getCode())){
                                    fieldAttrEntity.setAttrName(MultiUnitConstant.UNIT_NUM);
                                } else if (Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.STOCK_FLOW_BILL.getCode()) || Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.BATCH_FLOW_BILL.getCode()) || Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.SEQ_SEARCH.getCode())) {
                                    if (Objects.equals(fieldAttrEntity.getAttr(), SelectProductEnum.PRODUCT.getAttr())) {
                                        fieldAttrEntity.setFieldType(FieldTypeEnum.SELECT_PRODUCT.getType());
                                    } else if (Objects.equals(fieldAttrEntity.getAttr(), StockFlowBillEnum.WAREHOUSE_ID.getAttr())) {
                                        fieldAttrEntity.setFieldType(FieldTypeEnum.LINK_BUSINESS_MULTI.getType());
                                        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.WAREHOUSE.getCode());
                                    } else if (Objects.equals(fieldAttrEntity.getAttr(), StockFlowBillEnum.BUSINESS_ID.getAttr())) {
                                        fieldAttrEntity.setFieldType(FieldTypeEnum.BUSINESS_ID.getType());
                                    } else if (Objects.equals(fieldAttrEntity.getAttr(), StockFlowBillEnum.SHEET_NO.getAttr())) {
                                        fieldAttrEntity.setFieldType(FieldTypeEnum.REF_ID.getType());
                                    } else if (Objects.equals(fieldAttrEntity.getAttr(), BatchFlowBillEnum.BATCH.getAttr())) {
                                        fieldAttrEntity.setFieldType(FieldTypeEnum.BATCH.getType());
                                    } else if (Objects.equals(fieldAttrEntity.getAttr(), StockFlowBillEnum.TYPE.getAttr())) {
                                        fieldAttrEntity.setFieldType(FieldTypeEnum.BUSINESS_TYPE.getType());
                                    }
                                } else if (Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.STOCK_STANDING_BOOK.getCode())) {
                                    if (Objects.equals(fieldAttrEntity.getAttr(), SelectProductEnum.PRODUCT.getAttr())) {
                                        fieldAttrEntity.setFieldType(FieldTypeEnum.SELECT_PRODUCT.getType());
                                    } else if (Objects.equals(fieldAttrEntity.getAttr(), StockStandingBookEnum.WAREHOUSE_ID.getAttr())) {
                                        fieldAttrEntity.setFieldType(FieldTypeEnum.LINK_BUSINESS_MULTI.getType());
                                        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.WAREHOUSE.getCode());
                                    }
                                } else if(Objects.equals(screenListDTO.getBusinessType(),XbbRefTypeEnum.PAYMENT.getCode())){
                                    if(Objects.equals(fieldAttrEntity.getAttr(),PaymentEnum.SOURCE.getAttr())){
                                        continue;
                                    }
                                } else if (Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.CREDIT_LIMIT.getCode())) {
                                    // 临时额度、已用额度、可用额度是实时计算了，不做筛选
                                    List<String> creditFields = Arrays.asList(CreditLimitEnum.TEMPORARY_LIMIT.getAttr(), CreditLimitEnum.USED_LIMIT.getAttr(), CreditLimitEnum.AVAILABLE_LIMIT.getAttr());
                                    if (creditFields.contains(fieldAttrEntity.getAttr())) {
                                        continue;
                                    }
                                }
                                explainJsonArray.add(fieldAttrEntity);
                            }
                        }
                        // 详情页供货产品筛选
                        if (Objects.equals(fieldAttrEntity.getFieldType(),FieldTypeEnum.SELECT_PRODUCT.getType()) && Objects.equals(XbbRefTypeEnum.SUPPLIER.getCode(), screenListDTO.getBusinessType()) && Objects.equals(XbbRefTypeEnum.SUPPLIER_PRODUCT.getCode(), screenListDTO.getSubBusinessType())) {
                            FieldAttrEntity linkProductField = explainMap.get(SupplierEnum.PRODUCT_LIST.getAttr());
                            explainJsonArray.add(linkProductField);
                        }
                        if(scoreRuleHelp.isScoreField(screenListDTO.getBusinessType(),fieldAttrEntity.getAttr())){
                            //"评分"筛选（如果列表是按照"区间“展示分值,筛选项就是下拉框形式的;如果是"分数值"展示，筛选项就是数字的）
                            handleScoreScreenFiled(haveScoreScreen,fieldAttrEntity,screenListDTO,explainJsonArray);
                        }
                        if (Objects.equals(screenListDTO.getBusinessType(),XbbRefTypeEnum.TRANSFER.getCode()) && Objects.equals(TransferEnum.TRANSFER_TYPE.getAttr(), fieldAttrEntity.getAttr())) {
                            fieldAttrEntity.setFieldType(FieldTypeEnum.COMBO.getType());
                        }
                    }
                    value = value == null ? "" : value;
                } else {
                    explainJsonArray = explainScreenListVO.getFormExplainList();
                }
            }
            if (StringUtil.isNotEmpty(value)) {
                screenListVO.setScreen(value.split(","));
            }
            if (Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.SEQ_SEARCH.getCode())) {
                // 库存查询禁用筛选设置
                screenListVO.setHideFilter(1);
            }
            screenListVO.setFormExplainList(explainJsonArray);
            if (Objects.equals(screenListDTO.getPlatform(), PlatFormEnum.WEB.getValue())) {
                setSpecialScreens(screenListDTO, screenListVO, explainScreenListVO.getExplainList());
            } else {
                formatAppFilter(screenListDTO, screenListVO);
            }
            screenListVO.setScreenList(screenJsonArray);

        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("redis获取常用筛选项出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return screenListVO;
    }

    @Override
    public ScreenListVO forDistributor(Screen4DistributorDTO screen4DistributorDTO) throws XbbException {
        String systemCode = screen4DistributorDTO.getSystemCode();
        Integer byOrder = screen4DistributorDTO.getByOrder();
        if (Objects.equals(SystemCodeEnum.CUSTOMER_DELIVERY_ANALYSIS_CHART.getSystemCode(),screen4DistributorDTO.getSystemCode())&& Objects.equals(byOrder,0)) {
            return null;
        }
        ScreenListVO screenListVO = new ScreenListVO();
        ExplainScreenListDTO explainScreenListDTO = new ExplainScreenListDTO();
        BeanUtil.copyProperties(screen4DistributorDTO, explainScreenListDTO);

        JSONObject distributorName = new JSONObject();
        JSONObject productName = new JSONObject();
        //查询经销商名称的字段、查询产品名称的字段
        //经销商名称
        List<Long> distributorFormIdList = paasFormModel.getFormIdList4Distributor(XbbRefTypeEnum.CONTRACT.getCode(), screen4DistributorDTO.getCorpid(), 1);
        screenListVO.setFormId(distributorFormIdList.get(0));
        explainScreenListDTO.setBusinessType(XbbRefTypeEnum.CONTRACT.getCode());
        explainScreenListDTO.setFormId(distributorFormIdList.get(0));
        ExplainScreenListVO explainScreenListVO = paasFormExplainService.screenList(explainScreenListDTO);
        JSONArray distributorExplain = explainScreenListVO.getFormExplainList();
        for (int i = 0; i < distributorExplain.size(); i++) {
            JSONObject jsonObject = distributorExplain.getJSONObject(i);
            if (Objects.equals(OrderEnum.LINK_DISTRIBUTOR.getAttr(), jsonObject.getString("attr"))){
                //List<ConditionClass> conditions = ConditionListHelp.getConditionList(FieldTypeEnum.USER,0);
                //jsonObject.put("whereList",conditions);
                distributorName = jsonObject;
            }
            if (Objects.equals(OrderEnum.PRODUCT.getAttr(), jsonObject.getString("attr"))){
                //List<ConditionClass> conditions = ConditionListHelp.getConditionList(FieldTypeEnum.SELECT_PRODUCT,0);
                //jsonObject.put("whereList",conditions);
                productName = jsonObject;
            }
        }
        JSONArray salesExplainList = new JSONArray();
        salesExplainList.add(distributorName);
        JSONArray deliveryExplainList = new JSONArray();
        deliveryExplainList.add(productName);
        deliveryExplainList.add(distributorName);
        if (Objects.equals(SystemCodeEnum.CUSTOMER_SALES_ANALYSIS_CHART.getSystemCode(),systemCode)) {
            screenListVO.setFormExplainList(salesExplainList);
        }else{
            screenListVO.setFormExplainList(deliveryExplainList);
        }
        return screenListVO;
    }

    /**
     * 按照评分区间，处理“评分”筛选项
     * @param haveScoreScreen 是否支持评分筛选
     * @param fieldAttrEntity 字段
     * @param screenListDTO
     * @param explainJsonArray
     * @throws XbbException
     */
    private void handleScoreScreenFiled(Boolean haveScoreScreen,FieldAttrEntity fieldAttrEntity , ScreenListDTO screenListDTO,JSONArray explainJsonArray) throws XbbException {
        //先移除 explainJsonArray  中的score 字段，之前的通用逻辑把它弄进来了
        List<FieldAttrEntity> fieldAttrEntities = JSONArray.parseArray(explainJsonArray.toJSONString(), FieldAttrEntity.class);
        fieldAttrEntities.removeIf(item->Objects.equals(item.getAttr(),fieldAttrEntity.getAttr()));
        //根据规则判断，是否需要添加“评分”
        String corpid = screenListDTO.getCorpid();
        Long formId = screenListDTO.getFormId();
        //业务类型是支持评分的，并且评分展示是"区间"
        if(haveScoreScreen){
            //如果评分区间展示，那么特殊处理一下筛选项
            if(scoreRangeModel.isRangWithScoreShowType(corpid,formId)){
                fieldAttrEntity.setFieldType(FieldTypeEnum.SCORE_RANGE.getType());
                fieldAttrEntity.setItems(scoreRangeService.getItems4ScoreRangeScreen(screenListDTO.getCorpid(), screenListDTO.getFormId()));
            }
            explainJsonArray.add(fieldAttrEntity);
        }
    }

    @Override
    public ScreenListVO relationClueScreenList(RelationClueScreenListDTO screenListDTO) throws XbbException   {
        ScreenListVO screenListVO= new ScreenListVO();
        Integer throughCode = screenListDTO.getThroughCode();
        //关联销售线索列表，筛选条件是写死的（创建时间 和 线索状态）
        Map<String, Object> param = new HashMap<>(4);
        param.put("corpid", screenListDTO.getCorpid());
        param.put("businessType", XbbRefTypeEnum.CLUE.getCode());
        param.put("del", 0);
        List<PaasFormExplainEntity> explainEntities = paasFormExplainModel.findEntitys(param);
        if(CollectionUtils.isEmpty(explainEntities)){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_EXPLAIN_NOT_EXIST);
        }
        PaasFormExplainEntity paasFormExplainEntity = explainEntities.get(0);
        List<FieldAttrEntity> explainList = JSONArray.parseArray(paasFormExplainEntity.getExplains(), FieldAttrEntity.class);
        List<FieldAttrEntity> collect = explainList.stream().filter(fieldAttrEntity -> Arrays.asList(ClueEnum.ADD_TIME.getAttr(), ClueEnum.CLUE_STATUS.getAttr()).contains(fieldAttrEntity.getAttr())).collect(Collectors.toList());
        for(FieldAttrEntity  fieldAttrEntity : collect){
            if(ClueEnum.CLUE_STATUS.getAttr().equals(fieldAttrEntity.getAttr())){
                //根据穿透code设置默认值
                if(Objects.nonNull(throughCode)){
                    MarketActivityThroughEnum marketActivityThroughEnum = MarketActivityThroughEnum.getByCode(throughCode);
                    DefaultAttrPoJo defaultAttrPoJo = new  DefaultAttrPoJo();
                    JSONObject json = new JSONObject();
                    switch (marketActivityThroughEnum){
                        case EFFECTIVE_CLUE:
                            //有效线索指的是不包含“无效线索”状态的其他线索。这里默认值取“无效线索”,配合“不包含”条件，一起展示
                            json.put("throughCode",ClueStatusEnum.INVALID.getCode());
                            json.put("value",ClueStatusEnum.INVALID.getName());
                            defaultAttrPoJo.setDefaultValue(json);
                            break;
                        case TRANSFORMED_CLUE:
                            json.put("throughCode",ClueStatusEnum.TRANSFORMED.getCode());
                            json.put("value",ClueStatusEnum.TRANSFORMED.getName());
                            defaultAttrPoJo.setDefaultValue(json);
                            break;
                        case ALL_CLUE:
                        default:
                            break;
                    }
                    fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
                }
            }
        }
        screenListVO.setFormExplainList(JSONArray.parseArray(JSON.toJSONString(collect)));
        screenListVO.setScreen(ClueEnum.getMarketActivityTalScreenList());
        return screenListVO;
    }

    /**
     * 获取rediskEey
     * @param subBusinessType
     * @param corpid
     * @param appId
     * @param formId
     * @param userId
     * @return
     */
    private String getRrdisKey(Integer subBusinessType, String corpid, Long appId, Long formId, String userId) {
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(subBusinessType);
        switch (xbbRefTypeEnum){
            case STOCK_SEARCH:
            case WAIT_PURCHASE:
            case WAIT_PRODUCE:
            case WAIT_OUTSTOCK:
            case WAIT_INSTOCK_PURCHASE:
                return corpid;
            case ORI_STOCK:
                return "0";
            default:
                return corpid+"_"+ appId + "_" + formId + "_" + userId;
        }
    }

    /**
     * 获取前缀
     * @param businessType
     * @param subBusinessType
     * @return
     */
    private String getRrdisPrefix(Integer businessType, Integer subBusinessType) {
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(subBusinessType);
        switch (xbbRefTypeEnum){
            case STOCK_SEARCH:
                return UserConfigEnum.STOCK_FORM_COMMON_FILTER.getAlias();
            case WAIT_PURCHASE:
                if (Objects.equals(businessType,XbbRefTypeEnum.CONTRACT.getCode())){
                    return "waitPurchaseContractFilter";
                }else {
                    return "waitPurchaseProductFilter";
                }
            case WAIT_PRODUCE:
                if (Objects.equals(businessType,XbbRefTypeEnum.CONTRACT.getCode())){
                    return "waitProduceContractFilter";
                }else {
                    return "waitProduceProductFilter";
                }
            case WAIT_OUTSTOCK:
                if (Objects.equals(businessType,XbbRefTypeEnum.CONTRACT.getCode())){
                    return "waitOutstockContractFilter";
                }else if (Objects.equals(businessType,XbbRefTypeEnum.PRODUCT.getCode())){
                    return "waitOutstockProductFilter";
                }
            case WAIT_INSTOCK_PURCHASE:
                if (Objects.equals(businessType,XbbRefTypeEnum.PURCHASE.getCode())){
                    return "waitInstockPurchaseFilter";
                }else if (Objects.equals(businessType,XbbRefTypeEnum.PRODUCT.getCode())){
                    return "waitInstockProductFilter";
                }
            case ORI_STOCK:
                return "warehouseOriStockFilter";
            case SUPPLIER_PRODUCT:
                return "supplierProductFilter";
            case KNOWLEDGE_BASE:
                return "knowledgeBaseFilter";
            default:
               return UserConfigEnum.FORM_COMMON_FILTER.getAlias();
        }
    }

    /**
     * 公海退回时间筛选处理
     * @param explainJsonArray
     * @param fieldAttrEntity
     * @param subBusinessType
     * 创建时间 2019/6/4 10:51 AM
     * 修改时间 2019/6/4 10:51 AM
     * @author chy
     * @since v1.0
     * @version v1.0
     */
    private void formatBackPublicDate(JSONArray explainJsonArray, FieldAttrEntity fieldAttrEntity, Integer subBusinessType) {
        if (Objects.equals(ListBusinessTypeEnum.CUSTOMER_PUBLIC.getSubBusinessType(), subBusinessType) || Objects.equals(ListBusinessTypeEnum.CLUE_PUBLIC.getSubBusinessType(), subBusinessType)) {
            explainJsonArray.add(fieldAttrEntity);
        }
    }

    private void formatAddress(JSONArray explainJsonArray, FieldAttrEntity fieldAttrEntity) {
        String attr = fieldAttrEntity.getAttr();
//        explainJsonArray.add(fieldAttrEntity);
        String attrName = fieldAttrEntity.getAttrName();
        FieldAttrEntity result = new FieldAttrEntity();
        BeanUtil.copyProperties(fieldAttrEntity, result);
        result.setAttr(attr+"." + PaasConstant.PROVINCE);
        result.setAttrName(attrName + "-" + "省");
        explainJsonArray.add(result);
        result = new FieldAttrEntity();
        BeanUtil.copyProperties(fieldAttrEntity, result);
        result.setAttr(attr+"." + PaasConstant.CITY);
        result.setAttrName(attrName + "-" + "市");
        explainJsonArray.add(result);
        result = new FieldAttrEntity();
        BeanUtil.copyProperties(fieldAttrEntity, result);
        result.setAttr(attr+"." + PaasConstant.DISTRICT);
        result.setAttrName(attrName + "-" + "区/县");
        explainJsonArray.add(result);
        result = new FieldAttrEntity();
        BeanUtil.copyProperties(fieldAttrEntity, result);
        result.setAttr(attr+"." + PaasConstant.ADDRESS);
        result.setAttrName(attrName + "-" + "详细地址");
        explainJsonArray.add(result);
    }

    @Override
    public ScreenAddVO delScreenAdd(ScreenAddDTO screenAddDTO) throws XbbException {
        ScreenAddVO screenAddVO = new ScreenAddVO();
        try {
            String corpid = screenAddDTO.getCorpid();
            Long appId = screenAddDTO.getAppId();
            Long formId = screenAddDTO.getFormId();
            String key = corpid+"_"+String.valueOf(appId) + "_" + String.valueOf(formId);
            String screens = "";
            if (screenAddDTO.getScreenList() != null && !screenAddDTO.getScreenList().isEmpty()) {
                for (String searchItem: screenAddDTO.getScreenList()) {
                    if(StringUtil.isEmpty(screens)){
                        screens = searchItem;
                    }else{
                        screens += "," + searchItem;
                    }
                }
            }
            // 保存到数据库中
            UserConfigAddDTO userConfigAddDTO = new UserConfigAddDTO();
            BeanUtil.copyProperties(screenAddDTO, userConfigAddDTO);
            String configAlias = UserConfigEnum.FORM_COMMON_FILTER_DEL.getAlias() + "_" +key;
            userConfigAddDTO.setConfigName(UserConfigEnum.FORM_COMMON_FILTER_DEL.getName());
            userConfigAddDTO.setConfigAlias(configAlias);
            userConfigAddDTO.setConfigValue(screens);
            UserConfigAddVO userConfigAddVO = userConfigService.save(userConfigAddDTO);
            screenAddVO.setUserConfigId(userConfigAddVO.getUserConfigId());
            paasRedisHelper.setValue(RedisPrefixConstant.FORM_COMMON_FILTER_DEL, key, screens, TimeConstant.SEARCH_EFFECTIVE_TIME);
        } catch (Exception e) {
            LOG.error("redis设置常用筛选项出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return screenAddVO;
    }

    @Override
    public ScreenListVO delScreenList(ScreenListDTO screenListDTO) throws XbbException {
        ScreenListVO screenListVO = new ScreenListVO();
        try {
            String corpid = screenListDTO.getCorpid();
            Long appId = screenListDTO.getAppId();
            Long formId = screenListDTO.getFormId();
            String key = corpid+"_"+ String.valueOf(appId) + String.valueOf(formId);
            ExplainScreenListDTO explainScreenListDTO = new ExplainScreenListDTO();
            BeanUtil.copyProperties(screenListDTO, explainScreenListDTO);
            ExplainScreenListVO explainScreenListVO = paasFormExplainService.screenList(explainScreenListDTO);
            JSONArray explainJsonArray = new JSONArray();
            JSONArray screenJsonArray = new JSONArray();
            if(explainScreenListVO  != null && explainScreenListVO .getFormExplainList().size() > 0) {
                String value = paasRedisHelper.getValue(RedisPrefixConstant.FORM_COMMON_FILTER, key);
                if (StringUtil.isEmpty(value)) {
                    String configName = UserConfigEnum.FORM_COMMON_FILTER_DEL.getAlias() + "_" +key;
                    UserConfigEntity userConfigEntity = userConfigModel.getByUserId(screenListDTO.getUserId(), screenListDTO.getCorpid(), configName);
                    if(userConfigEntity != null) {
                        value = userConfigEntity.getConfigValue();
                    }else{
                        explainJsonArray = explainScreenListVO.getFormExplainList();
                    }
                }
                if(StringUtil.isNotEmpty(value)) {
                    String[] array = value.split(",");
                    Map<String, FieldAttrEntity> explainMap = ExplainUtil.getExplainMap(JSONArray.toJSONString(explainScreenListVO.getFormExplainList()), null);
                    for(String string : array) {
                        if (explainMap.containsKey(string)) {
                            screenJsonArray.add(explainMap.get(string));
                            explainMap.remove(string);
                        }
                    }
                    for(Map.Entry<String,FieldAttrEntity> item: explainMap.entrySet()) {
                        explainJsonArray.add(item.getValue());
                    }

                }
            }
            screenListVO.setFormExplainList(explainJsonArray);
            screenListVO.setScreenList(screenJsonArray);

        } catch (Exception e) {
            LOG.error("redis获取常用筛选项出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return screenListVO;
    }

    @Override
    public ScreenAddVO selectScreenAdd(ScreenAddDTO screenAddDTO) throws XbbException {
        ScreenAddVO screenAddVO = new ScreenAddVO();
        try {
            String corpid = screenAddDTO.getCorpid();
            Long appId = screenAddDTO.getAppId();
            Long formId = screenAddDTO.getFormId();
            String userId = screenAddDTO.getUserId();
            String attr = screenAddDTO.getAttr();
            String key = corpid+"_"+ appId + "_" + formId + "_" + attr + "_" + userId;
            String screens = "";
            if (screenAddDTO.getScreenList() != null && !screenAddDTO.getScreenList().isEmpty()) {
                for (String searchItem: screenAddDTO.getScreenList()) {
                    if(StringUtil.isEmpty(screens)){
                        screens = searchItem;
                    }else{
                        screens += "," + searchItem;
                    }
                }
            }
            // 保存到数据库中
            UserConfigAddDTO userConfigAddDTO = new UserConfigAddDTO();
            BeanUtil.copyProperties(screenAddDTO, userConfigAddDTO);
            String configAlias = UserConfigEnum.SELECT_PRODUCT_COMMON_FILTER.getAlias() + "_" +key;
            userConfigAddDTO.setConfigName(UserConfigEnum.SELECT_PRODUCT_COMMON_FILTER.getName());
            userConfigAddDTO.setConfigAlias(configAlias);
            userConfigAddDTO.setConfigValue(screens);
            UserConfigAddVO userConfigAddVO = userConfigService.save(userConfigAddDTO);
            screenAddVO.setUserConfigId(userConfigAddVO.getUserConfigId());
            paasRedisHelper.setValue(RedisPrefixConstant.SELECT_PRODUCT_COMMON_FILTER, key, screens, TimeConstant.SEARCH_EFFECTIVE_TIME);
        } catch (Exception e) {
            LOG.error("redis设置常用筛选项出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return screenAddVO;
    }

    @Override
    public ScreenAddVO screenSelectPurchaseAdd(ScreenAddDTO screenAddDTO) throws XbbException {
        ScreenAddVO screenAddVO = new ScreenAddVO();
        try {
            String corpid = screenAddDTO.getCorpid();
            Long appId = screenAddDTO.getAppId();
            Long formId = screenAddDTO.getFormId();
            String userId = screenAddDTO.getUserId();
            String attr = screenAddDTO.getAttr();
            String key = corpid+"_"+ appId + "_" + formId + "_" + attr + "_" + userId;
            String screens = "";
            if (screenAddDTO.getScreenList() != null && !screenAddDTO.getScreenList().isEmpty()) {
                for (String searchItem: screenAddDTO.getScreenList()) {
                    if(StringUtil.isEmpty(screens)){
                        screens = searchItem;
                    }else{
                        screens += "," + searchItem;
                    }
                }
            }
            // 保存到数据库中
            UserConfigAddDTO userConfigAddDTO = new UserConfigAddDTO();
            BeanUtil.copyProperties(screenAddDTO, userConfigAddDTO);
            String configAlias = UserConfigEnum.SELECT_PURCHASE_COMMON_FILTER.getAlias() + "_" +key;
            userConfigAddDTO.setConfigName(UserConfigEnum.SELECT_PURCHASE_COMMON_FILTER.getName());
            userConfigAddDTO.setConfigAlias(configAlias);
            userConfigAddDTO.setConfigValue(screens);
            UserConfigAddVO userConfigAddVO = userConfigService.save(userConfigAddDTO);
            screenAddVO.setUserConfigId(userConfigAddVO.getUserConfigId());
            paasRedisHelper.setValue(RedisPrefixConstant.SELECT_PURCHASE_COMMON_FILTER, key, screens, TimeConstant.SEARCH_EFFECTIVE_TIME);
        } catch (Exception e) {
            LOG.error("redis设置常用筛选项出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return screenAddVO;
    }

    @Override
    public ScreenAddVO screenSelectContractAdd(ScreenAddDTO screenAddDTO) throws XbbException {
        ScreenAddVO screenAddVO = new ScreenAddVO();
        try {
            String corpid = screenAddDTO.getCorpid();
            Long appId = screenAddDTO.getAppId();
            Long formId = screenAddDTO.getFormId();
            String userId = screenAddDTO.getUserId();
            String attr = screenAddDTO.getAttr();
            String key = corpid+"_"+ appId + "_" + formId + "_" + attr + "_" + userId;
            String screens = "";
            if (screenAddDTO.getScreenList() != null && !screenAddDTO.getScreenList().isEmpty()) {
                for (String searchItem: screenAddDTO.getScreenList()) {
                    if(StringUtil.isEmpty(screens)){
                        screens = searchItem;
                    }else{
                        screens += "," + searchItem;
                    }
                }
            }
            // 保存到数据库中
            UserConfigAddDTO userConfigAddDTO = new UserConfigAddDTO();
            BeanUtil.copyProperties(screenAddDTO, userConfigAddDTO);
            String configAlias = UserConfigEnum.SELECT_CONTRACT_COMMON_FILTER.getAlias() + "_" +key;
            userConfigAddDTO.setConfigName(UserConfigEnum.SELECT_CONTRACT_COMMON_FILTER.getName());
            userConfigAddDTO.setConfigAlias(configAlias);
            userConfigAddDTO.setConfigValue(screens);
            UserConfigAddVO userConfigAddVO = userConfigService.save(userConfigAddDTO);
            screenAddVO.setUserConfigId(userConfigAddVO.getUserConfigId());
            paasRedisHelper.setValue(RedisPrefixConstant.SELECT_CONTRACT_COMMON_FILTER, key, screens, TimeConstant.SEARCH_EFFECTIVE_TIME);
        } catch (Exception e) {
            LOG.error("redis设置常用筛选项出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return screenAddVO;
    }

    @Override
    public ScreenListVO selectScreenList(ScreenListDTO screenListDTO) throws XbbException {
        ScreenListVO screenListVO = new ScreenListVO();
        try {
            String corpid = screenListDTO.getCorpid();
            Long appId = screenListDTO.getAppId();
            Long formId = screenListDTO.getFormId();
            String userId = screenListDTO.getUserId();
            String attr = screenListDTO.getAttr();
            String key;
            if (Objects.equals(XbbRefTypeEnum.PRICE_SET_PRODUCT.getCode(), screenListDTO.getBusinessType())) {
                key = corpid+"_"+ appId + "_" + formId + "_" + attr + "_" + screenListDTO.getBusinessType() + userId;
                attr = null;
            } else {
                key = corpid+"_"+ appId + "_" + formId + "_" + attr + "_" + userId;
            }
            String explainStr;
            Integer businessType = screenListDTO.getBusinessType();
            boolean isSourceType = Objects.equals(businessType, XbbRefTypeEnum.REFUND.getCode()) || Objects.equals(businessType, XbbRefTypeEnum.RETURNED_PURCHASE.getCode()) || Objects.equals(businessType, XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode())
                        || Objects.equals(businessType, XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode()) || Objects.equals(businessType, XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode())
                        || Objects.equals(businessType, XbbRefTypeEnum.PURCHASE_INSTOCK.getCode()) || Objects.equals(businessType, XbbRefTypeEnum.REFUND_INSTOCK.getCode())
                        || Objects.equals(businessType, XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode());
            JSONArray formExplainList = new JSONArray();
            JSONArray screenJsonArray = new JSONArray();
            screenListVO.setScreen(new String[]{});
            boolean categoryId = StringUtil.isNotEmpty(attr);
            boolean warehouse = StringUtil.isNotEmpty(attr);

            FieldAttrEntity selectProduct = null;

            if (StringUtil.isEmpty(attr)){
                PaasFormEntityExt paasFormEntity = paasFormModel.getByBusinessType(XbbRefTypeEnum.PRODUCT.getCode(),corpid);
//                PaasFormExplainEntity paasFormExplainEntity = paasFormExplainModel.getByFormId(paasFormEntity.getId(),corpid);
//                List<FieldAttrEntity> explainList = JSONArray.parseArray(paasFormExplainEntity.getExplains(),FieldAttrEntity.class);
//                HandlerExplainDTO handlerExplainDTO = new HandlerExplainDTO();
//                BeanUtil.copyProperties(screenListDTO, handlerExplainDTO, false);
//                handlerExplainDTO.setExplainList(explainList);
//                handlerExplainDTO.setPaasFormEntityExt(paasFormEntity);
//                HandlerExplainVO handlerExplainVO = formDataAddFormExplainHandlerName.handleExplain(handlerExplainDTO);
                ExplainScreenListDTO explainScreenListDTO = new ExplainScreenListDTO();
                BeanUtil.copyProperties(screenListDTO, explainScreenListDTO);

                explainScreenListDTO.setBusinessType(XbbRefTypeEnum.PRODUCT.getCode());
                explainScreenListDTO.setFormId(paasFormEntity.getId());
                explainScreenListDTO.setSubBusinessType(XbbRefTypeEnum.PRODUCT.getCode());
                ExplainScreenListVO explainScreenListVO = paasFormExplainService.screenList(explainScreenListDTO);
                List<FieldAttrEntity> explainList = explainScreenListVO.getFormExplainList().toJavaList(FieldAttrEntity.class);
                Iterator<FieldAttrEntity> iterator = explainList.iterator();
                while (iterator.hasNext()){
                    FieldAttrEntity item = iterator.next();
                    if (!ShowTypeEnum.listShow(item.getShowType()) || Objects.equals(FieldTypeEnum.getFieldTypeEnum(item.getFieldType()).getEsalias(),EsAliasEnum.FILE.getEsAlias())){
                        iterator.remove();
                    } else if (Objects.equals(item.getAttr(), ProductEnum.WAREHOUSE.getAttr())) {
                        iterator.remove();
                    }
                }
                if (Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode())
                        || Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.WAIT_PURCHASE.getCode())
                        || Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.WAIT_OUTSTOCK.getCode())){
                    Iterator<FieldAttrEntity> iterators = explainList.iterator();
                    while (iterators.hasNext()){
                        FieldAttrEntity fieldAttrEntity = iterators.next();
                        if (!Objects.equals(fieldAttrEntity.getAttr(), ProductEnum.NAME.getAttr())
                                &!Objects.equals(fieldAttrEntity.getAttr(), ProductEnum.SERIALNO.getAttr())
                                &!Objects.equals(fieldAttrEntity.getAttr(), ProductEnum.UNIT.getAttr())
                                &!Objects.equals(fieldAttrEntity.getAttr(), ProductEnum.SPECIFICATION.getAttr())
                                &!Objects.equals(fieldAttrEntity.getAttr(), ProductEnum.SUPPLIER.getAttr())){
                            iterators.remove();
                            continue;
                        }
                        if (!Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.WAIT_PURCHASE.getCode()) && Objects.equals(fieldAttrEntity.getAttr(), ProductEnum.SUPPLIER.getAttr())){
                            iterators.remove();
                        }
                    }
                }
                formExplainList.addAll(explainList);
            }else {
                //工单逻辑特殊处理
                if (Objects.equals(businessType, XbbRefTypeEnum.WORK_ORDER.getCode())){
                    if (Objects.isNull(formId) || Objects.equals(formId,0L)){
                        WorkOrderExplainEntity explainEntityExt = workOrderExplainModel.getDefaultAllListExplain(corpid);
                        explainStr = explainEntityExt.getExplains();
                    }else {
                        WorkOrderExplainEntityExt explainEntityExt = workOrderExplainModel.getByFormId(formId, corpid);
                        explainStr = explainEntityExt.getExplains();
                    }
                }else{
                    PaasFormExplainEntity paasFormExplainEntity;
                    if (Objects.equals(businessType,XbbRefTypeEnum.ORI_STOCK.getCode())){
                        paasFormExplainEntity = paasFormExplainModel.getOriStockForm();
                    }else if (Objects.equals(businessType, XbbRefTypeEnum.FULL_DISCOUNT_COUPON.getCode()) || Objects.equals(businessType, XbbRefTypeEnum.SPECIAL_GOODS.getCode())){
                        paasFormExplainEntity = paasFormExplainModel.getSystemDefaultExplain(businessType);
                    }else {
                        paasFormExplainEntity = paasFormExplainModel.getByFormId(formId,corpid);
                    }
                    explainStr = paasFormExplainEntity.getExplains();
                }
                List<FieldAttrEntity> explainList = JSONArray.parseArray(explainStr,FieldAttrEntity.class);
                for (FieldAttrEntity fieldAttrEntity : explainList){
                    if (Objects.equals(fieldAttrEntity.getFieldType(), FieldTypeEnum.SELECT_PRODUCT.getType()) && Objects.equals(fieldAttrEntity.getAttr(),attr)){
                        List<? extends FieldAttrEntity> subFormFieldAttrList = fieldAttrEntity.getSubForm().getItems();
                        for (FieldAttrEntity entity : subFormFieldAttrList){
                            if (Objects.equals(entity.getAttr(), SelectProductEnum.PRODUCT.getAttr())){
                                List<LinkedAttrPoJo> linkedAttrPoJoList = entity.getLinkInfo().getLinkedAttr();
//                                Iterator<LinkedAttrPoJo> iterator = linkedAttrPoJoList.iterator();
//                                while (iterator.hasNext()){
//                                    LinkedAttrPoJo attrPoJo = iterator.next();
//                                    if (attrPoJo.getAttr().equals(ProductEnum.WAREHOUSE.getAttr())){
//                                        warehouse = false;
//                                    }
//                                    if (attrPoJo.getAttr().equals(ProductEnum.CATEGORY_ID.getAttr())){
//                                        categoryId = false;
//                                    }
//                                    if (Objects.equals(FieldTypeEnum.getFieldTypeEnum(attrPoJo.getFieldType()).getEsalias(),EsAliasEnum.FILE.getEsAlias())){
//                                        iterator.remove();
//                                    }
//                                }
                                FormatExplainDTO formatExplainDTO = new FormatExplainDTO();
                                BeanUtil.copyProperties(screenListDTO,formatExplainDTO);
                                formatExplainDTO.setProductField(fieldAttrEntity);
//                                relativeProductHelp.addProductLinkAttr(XbbRefTypeEnum.getByCode(businessType),entity.getLinkInfo().getLinkedAttr(),formatExplainDTO);
                                if(CollectionUtils.isNotEmpty(linkedAttrPoJoList)) {
                                    linkedAttrPoJoList.forEach(item ->{
                                        if (Objects.nonNull(ProductEnum.getByAttr(item.getAttr()))){
                                            item.setAttrName(ProductEnum.getByAttr(item.getAttr()).getAttrName());
                                        }
                                    });
                                }
                                formExplainList = JSONArray.parseArray(JSONArray.toJSONString(linkedAttrPoJoList));
                            }
                        }
                        selectProduct = fieldAttrEntity;
                        break;
                    }
                }
            }
            // 这一段之前是注释掉了的 fixbug 24836
            if ((warehouse && !isSourceType) || (isSourceType && StringUtil.isEmpty(attr))){
                FieldAttrEntity fieldAttrEntity = new FieldAttrEntity();
                fieldAttrEntity.setAttr(ProductEnum.WAREHOUSE.getAttr());
                fieldAttrEntity.setAttrName(I18nMessageUtil.getMessage(StringConstant.PRODUCT_STOCK));
                fieldAttrEntity.setFieldType(ProductEnum.WAREHOUSE.getFieldType());
                screenJsonArray.add(fieldAttrEntity);
            }
            if ((categoryId && !isSourceType) || (isSourceType && StringUtil.isEmpty(attr))){
                FieldAttrEntity fieldAttrEntity = new FieldAttrEntity();
                fieldAttrEntity.setAttr(ProductEnum.CATEGORY_ID.getAttr());
                fieldAttrEntity.setAttrName(ProductEnum.CATEGORY_ID.getAttrName());
                fieldAttrEntity.setFieldType(ProductEnum.CATEGORY_ID.getFieldType());
                screenJsonArray.add(fieldAttrEntity);
            }
            if (isSourceType && StringUtil.isNotEmpty(attr)){
                FieldAttrEntity fieldAttrEntity;
                if (Objects.nonNull(selectProduct)) {
                    fieldAttrEntity = selectProduct;
                } else {
                    fieldAttrEntity = new FieldAttrEntity();
                    fieldAttrEntity.setAttr("selectProduct");
                    fieldAttrEntity.setAttrName(I18nMessageUtil.getMessage(I18nStringConstant.LINK_PRODUCT));
                    fieldAttrEntity.setFieldType(FieldTypeEnum.SELECT_PRODUCT.getType());
                }
                screenJsonArray.add(fieldAttrEntity);
                screenListVO.setScreen(fieldAttrEntity.getAttr().split(","));
                LinkInfoPojo linkInfoPojo = new LinkInfoPojo();
                linkInfoPojo.setLinkAppId(screenListDTO.getAppId());
                linkInfoPojo.setLinkFormId(screenListDTO.getFormId());
                linkInfoPojo.setLinkBusinessType(screenListDTO.getBusinessType());
                linkInfoPojo.setLinkSaasMark(screenListDTO.getSaasMark());
                screenListVO.setSourceInfo(linkInfoPojo);
                screenListVO.setHideFilter(1);
            } else {
                String value = paasRedisHelper.getValue(RedisPrefixConstant.SELECT_PRODUCT_COMMON_FILTER, key);
                if (StringUtil.isEmpty(value)) {
                    String configName = UserConfigEnum.SELECT_PRODUCT_COMMON_FILTER.getAlias() + "_" +key;
                    UserConfigEntity userConfigEntity = userConfigModel.getByUserId(screenListDTO.getUserId(), screenListDTO.getCorpid(), configName);
                    if(userConfigEntity != null) {
                        value = userConfigEntity.getConfigValue();
                    }
                }
                if (StringUtil.isNotEmpty(value)) {
                    screenListVO.setScreen(value.split(","));
                } else if (Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.COST_ADJUST.getCode())) {
                    // 产品一定要在成本调整单中选择产品的查询条件设置默认值
                    screenListVO.setScreen(CostAdjustProductEnum.getProductScreen());
                }else {
                    value = "num_13,text_1,serialNo,text_5,num_12";
                    screenListVO.setScreen(value.split(","));
                }
            }
            screenListVO.setFormExplainList(formExplainList);
            screenListVO.setScreenList(screenJsonArray);

        } catch (Exception e) {
            LOG.error("redis获取常用筛选项出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return screenListVO;
    }

    @Override
    public ScreenListVO screenSelectPurchaseList(ScreenListDTO screenListDTO) throws XbbException {
        ScreenListVO screenListVO = new ScreenListVO();
        try {
            String corpid = screenListDTO.getCorpid();
            Long appId = screenListDTO.getAppId();
            Long formId = screenListDTO.getFormId();
            String userId = screenListDTO.getUserId();
            String attr = screenListDTO.getAttr();
            String key = corpid+"_"+ appId + "_" + formId + "_" + attr + "_" + userId;
            JSONArray formExplainList = new JSONArray();
            JSONArray screenJsonArray = new JSONArray();
            screenListVO.setScreen(new String[]{});
            if (StringUtil.isEmpty(attr)){
                PaasFormEntityExt paasFormEntity = paasFormModel.getByBusinessType(XbbRefTypeEnum.PURCHASE.getCode(),corpid);
                ExplainScreenListDTO explainScreenListDTO = new ExplainScreenListDTO();
                BeanUtil.copyProperties(screenListDTO, explainScreenListDTO);
                explainScreenListDTO.setBusinessType(XbbRefTypeEnum.PURCHASE.getCode());
                explainScreenListDTO.setFormId(paasFormEntity.getId());
                explainScreenListDTO.setSubBusinessType(XbbRefTypeEnum.PURCHASE.getCode());
                ExplainScreenListVO explainScreenListVO = paasFormExplainService.screenList(explainScreenListDTO);
                List<FieldAttrEntity> explainList = explainScreenListVO.getFormExplainList().toJavaList(FieldAttrEntity.class);
                Iterator<FieldAttrEntity> iterator = explainList.iterator();
                while (iterator.hasNext()){
                    FieldAttrEntity item = iterator.next();
                    if (WaitInstockEnum.isPurchaseAndProduct(item.getAttr())){
                        iterator.remove();
                    }
                }
                formExplainList.addAll(explainList);
            }
            String value = paasRedisHelper.getValue(RedisPrefixConstant.SELECT_PURCHASE_COMMON_FILTER, key);
            if (StringUtil.isEmpty(value)) {
                String configName = UserConfigEnum.SELECT_PURCHASE_COMMON_FILTER.getAlias()+ "_" +key;
                UserConfigEntity userConfigEntity = userConfigModel.getByUserId(screenListDTO.getUserId(), screenListDTO.getCorpid(), configName);
                if(userConfigEntity != null) {
                    value = userConfigEntity.getConfigValue();
                }
            }
            if (StringUtil.isNotEmpty(value)) {
                screenListVO.setScreen(value.split(","));
            }else {
                value = "text_2,text_3,date_1,date_2,text_5,text_6,addTime,updateTime";
                screenListVO.setScreen(value.split(","));
            }
            screenListVO.setFormExplainList(formExplainList);
            screenListVO.setScreenList(screenJsonArray);
        } catch (Exception e) {
            LOG.error("redis获取常用筛选项出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return screenListVO;
    }

    @Override
    public ScreenListVO screenSelectContractList(ScreenListDTO screenListDTO) throws XbbException {
        ScreenListVO screenListVO = new ScreenListVO();
        try {
            String corpid = screenListDTO.getCorpid();
            Long appId = screenListDTO.getAppId();
            Long formId = screenListDTO.getFormId();
            String userId = screenListDTO.getUserId();
            String attr = screenListDTO.getAttr();
            String key = corpid+"_"+ appId + "_" + formId + "_" + attr + "_" + userId;
            JSONArray formExplainList = new JSONArray();
            JSONArray screenJsonArray = new JSONArray();
            screenListVO.setScreen(new String[]{});
            if (StringUtil.isEmpty(attr)){
                ExplainScreenListDTO explainScreenListDTO = new ExplainScreenListDTO();
                if (Objects.equals(screenListDTO.getDistributorMark(), DistributorMarkEnum.DISTRIBUTOR.getCode())) {
                    BeanUtil.copyProperties(screenListDTO, explainScreenListDTO);
                    explainScreenListDTO.setBusinessType(XbbRefTypeEnum.ORDER.getCode());
                    explainScreenListDTO.setFormId(formId);
                    explainScreenListDTO.setSubBusinessType(XbbRefTypeEnum.ORDER.getCode());
                }else {
                    BeanUtil.copyProperties(screenListDTO, explainScreenListDTO);
                    explainScreenListDTO.setBusinessType(XbbRefTypeEnum.CONTRACT.getCode());
                    explainScreenListDTO.setFormId(formId);
                    explainScreenListDTO.setSubBusinessType(XbbRefTypeEnum.CONTRACT.getCode());
                }
                ExplainScreenListVO explainScreenListVO = paasFormExplainService.screenList(explainScreenListDTO);
                List<FieldAttrEntity> explainList = explainScreenListVO.getFormExplainList().toJavaList(FieldAttrEntity.class);
                Iterator<FieldAttrEntity> iterator = explainList.iterator();
                while (iterator.hasNext()){
                    FieldAttrEntity fieldAttrEntity = iterator.next();
                    String contractAttr = fieldAttrEntity.getAttr();
                   if (!(Objects.equals(contractAttr, ContractEnum.NAME.getAttr())
                           || Objects.equals(contractAttr, ContractEnum.CONTRACT_NO.getAttr())
                           || Objects.equals(contractAttr, ContractEnum.LINK_CUSTOMER.getAttr())
                           || Objects.equals(contractAttr, ContractEnum.STATUS.getAttr())
                           || Objects.equals(contractAttr, ContractEnum.SIGN_TIME.getAttr())
                           || Objects.equals(contractAttr, ContractEnum.OWNER_ID.getAttr())
                           || Objects.equals(contractAttr, ContractEnum.MINOR_USER.getAttr())
                           || Objects.equals(contractAttr, FieldTypeEnum.ADDTIME.getAlias())
                           || Objects.equals(contractAttr, FieldTypeEnum.UPDATETIME.getAlias())
                           || Objects.equals(contractAttr, FieldTypeEnum.CREATORID.getAlias()))) {
                        iterator.remove();
                    }
                    fieldAttrEntity.setEditable(0);
                }
                formExplainList.addAll(explainList);
            }
            String value = paasRedisHelper.getValue(RedisPrefixConstant.SELECT_CONTRACT_COMMON_FILTER, key);
            if (StringUtil.isEmpty(value)) {
                String configName = UserConfigEnum.SELECT_CONTRACT_COMMON_FILTER.getAlias()+ "_" +key;
                UserConfigEntity userConfigEntity = userConfigModel.getByUserId(screenListDTO.getUserId(), screenListDTO.getCorpid(), configName);
                if(userConfigEntity != null) {
                    value = userConfigEntity.getConfigValue();
                }
            }
            if (StringUtil.isNotEmpty(value)) {
                screenListVO.setScreen(value.split(","));
            }else {
                value = "text_1,serialNo,text_2,date_1,text_6,ownerId,coUserId,creatorId,addTime,updateTime";
                screenListVO.setScreen(value.split(","));
            }
            screenListVO.setFormExplainList(formExplainList);
            screenListVO.setScreenList(screenJsonArray);
        } catch (Exception e) {
            LOG.error("redis获取常用筛选项出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return screenListVO;
    }

    @Override
    public ScreenListVO screenCustomerStatementList(ScreenListPojo screenListPojo) throws XbbException {
        ScreenListVO screenListVO = new ScreenListVO();
        try {
            String corpid = screenListPojo.getCorpid();
            Integer businessType = screenListPojo.getBusinessType();
            // 查询表单，解释
            PaasFormEntityExt paasFormEntityExt = paasFormModel.getByBusinessType(businessType, corpid);
            if (Objects.isNull(paasFormEntityExt)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100018.getCode(), I18nStringConstant.FORM_NOT_EXIST);
            }
            Long formId = paasFormEntityExt.getId();
            PaasFormExplainEntity explainEntity = paasFormExplainModel.getByFormId(formId, corpid);
            if (Objects.isNull(explainEntity)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100018.getCode(), I18nStringConstant.FORM_NOT_EXIST);
            }
            List<FieldAttrEntity> explainList = JSONArray.parseArray(explainEntity.getExplains(), FieldAttrEntity.class);
            //设置范围筛选选项
            setSpecialScreens(screenListPojo, screenListVO, null);
            //获取顶部和底部按钮
            List<ButtonPojo> topButtonList = new ArrayList<>();
            List<ButtonPojo> bottomPermissions = new ArrayList<>();
            FormDataListDTO formDataListDTO = new FormDataListDTO();
            BeanUtil.copyProperties(screenListPojo, formDataListDTO, true);
            //获取顶部和底部按钮(提取)
            formDataListSearchHelp.getTopAndButtonList(formDataListDTO, corpid, businessType, topButtonList, bottomPermissions, paasFormEntityExt, null);
            screenListVO.setFormId(formId);
            screenListVO.setAppId(paasFormEntityExt.getAppId());
            screenListVO.setMenuId(paasFormEntityExt.getMenuId());
            screenListVO.setHeadList(explainList);
            screenListVO.setTopPermissions(topButtonList);
            screenListVO.setBottomPermissions(bottomPermissions);
            screenListVO.setScreen(CustomerStatementEnum.CUSTOMER_ID.getAttr().split(SymbolConstant.COMMA_ENGLISH));
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("redis获取常用筛选项出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return screenListVO;
    }

    /**
     * 设置范围筛选选项
     *
     * @param screenListPojo
     * @param screenListVO
     * @param explainList
     * @autuor: long.rao
     * @date: 2020-02-26 14:00:00
     */
    private void setSpecialScreens(ScreenListPojo screenListPojo, ScreenListVO screenListVO, List<FieldAttrEntity> explainList) {
        List<SpecialListFieldPojo> specialListFieldPojos = new ArrayList<>();
        Map<String, String> map = new LinkedHashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        SpecialListFieldPojo rangeScreen = new SpecialListFieldPojo();
        Integer businessType = screenListPojo.getBusinessType();
        // 批次保质期查询不需要可见范围筛选
        if (Objects.equals(businessType, XbbRefTypeEnum.PRODUCT.getCode()) && Objects.equals(screenListPojo.getSubBusinessType(), XbbRefTypeEnum.GUARANTEE_SEARCH.getCode())) {
            ListGroupEnum listGroupEnum = ListGroupEnum.getByCode(screenListPojo.getFormId().intValue());
            if (Objects.equals(listGroupEnum.getRefType(), XbbRefTypeEnum.GUARANTEE_SEARCH.getCode())) {
                businessType = XbbRefTypeEnum.GUARANTEE_SEARCH.getCode();
            }
        }
        //待出库两个维度，范围筛选项统一
        if (Objects.equals(screenListPojo.getSubBusinessType(),XbbRefTypeEnum.WAIT_OUTSTOCK.getCode())){
            businessType = XbbRefTypeEnum.CONTRACT.getCode();
        }
        XbbRefTypeEnum type = XbbRefTypeEnum.getByCode(businessType);
        switch (type) {
            case CUSTOMER_MANAGEMENT:
            case SALES_OPPORTUNITY:
            case REFUND:
            case SUPPLIER:
            case BOM_BILL:
            case PRODUCTION_ORDER:
            case CLUE:
            case MARKET_ACTIVITY:
                if (Objects.equals(screenListPojo.getSubBusinessType(), XbbRefTypeEnum.CUSTOMER_RECYCLE.getCode()) || Objects.equals(screenListPojo.getSubBusinessType(), XbbRefTypeEnum.CLUE_RECYCLE.getCode())) {
                    // 回收站不需要范围筛选
                    return;
                }
                if (Objects.equals(screenListPojo.getSubBusinessType(), XbbRefTypeEnum.CUSTOMER_PUBLIC.getCode()) || Objects.equals(screenListPojo.getSubBusinessType(), XbbRefTypeEnum.CLUE_PUBLIC.getCode())) {
                    for (FieldAttrEntity fieldAttrEntity : explainList) {
                        if (Objects.equals(fieldAttrEntity.getAttr(), FieldTypeEnum.OWNERID.getAlias())) {
                            map.put(FieldTypeEnum.PRE_OWNER_ID.getAlias(), FieldTypeEnum.PRE_OWNER_ID.getDescription());
                            break;
                        }
                    }
                    break;
                }
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), FieldTypeEnum.OWNERID.getAlias())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    } else if (Objects.equals(fieldAttrEntity.getAttr(), FieldTypeEnum.COUSERID.getAlias())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    }
                }
                break;
            case CONTACT:
            case SUPPLIER_CONTACT:
                map.put(FieldTypeEnum.OWNERID.getAlias(), I18nMessageUtil.getMessage(CommonConstant.MAIN_USER));
                map.put(FieldTypeEnum.COUSERID.getAlias(), I18nMessageUtil.getMessage(CommonConstant.COLLABORATOR));
                break;
            case RETURNED_PURCHASE:
            case ASSEMBLE:
            case PURCHASE_INSTOCK:
            case REFUND_INSTOCK:
            case OTHER_INSTOCK:
            case PRODUCTION_INSTOCK:
            case RETURNED_MATERIEL_INSTOCK:
            case CONTRACT_OUTSTOCK:
            case RETURNED_PURCHASE_OUTSTOCK:
            case OTHER_OUTSTOCK:
            case PRODUCTION_MATERIEL_OUTSTOCK:
            case WORK_ORDER_OUTSTOCK:
            case INVENTORY:
            case TRANSFER:
            case PAY_PLAN:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), FieldTypeEnum.OWNERID.getAlias())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                        break;
                    }
                }
                break;
            case PAYMENT:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), FieldTypeEnum.OWNERID.getAlias())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                        break;
                    }
                }
                Map<String, String> sourceMap = new LinkedHashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                SpecialListFieldPojo serialNo = new SpecialListFieldPojo();
                PaymentSourceTypeEnum.getMapByFieldType(FieldTypeEnum.SOURCE.getType(), sourceMap);
                List<ItemPoJo> itemPoJo= gerItems(sourceMap);
                serialNo.setItems(itemPoJo);
                serialNo.setAttr(FieldTypeEnum.SOURCE.getAlias());
                serialNo.setAttrName(FieldTypeEnum.SOURCE.getDescription());
                serialNo.setFieldType(FieldTypeEnum.SOURCE.getType());
                specialListFieldPojos.add(serialNo);
                screenListVO.setSpecialScreens(specialListFieldPojos);
                break;
            case QUOTATION:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), QuotationEnum.OWNER_ID.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    } else if (Objects.equals(fieldAttrEntity.getAttr(), QuotationEnum.MINOR_USER.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    } else if (Objects.equals(fieldAttrEntity.getAttr(), QuotationEnum.QUOTATION_PERSON.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    }
                }
                break;
            case CONTRACT:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), ContractEnum.OWNER_ID.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    } else if (Objects.equals(fieldAttrEntity.getAttr(), ContractEnum.MINOR_USER.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    } else if (Objects.equals(fieldAttrEntity.getAttr(), ContractEnum.SIGN_PERSON.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    }
                }
                break;
            case PURCHASE:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), PurchaseEnum.OWNER_ID.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    } else if (Objects.equals(fieldAttrEntity.getAttr(), PurchaseEnum.COUSERID.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    } else if (Objects.equals(fieldAttrEntity.getAttr(), PurchaseEnum.SIGNER_ID.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    }
                }
                break;
            case PAYMENT_SHEET:
            case PAY_SHEET:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), FieldTypeEnum.OWNERID.getAlias())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    } else if (Objects.equals(fieldAttrEntity.getAttr(), FieldTypeEnum.COUSERID.getAlias())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    } else if (Objects.equals(fieldAttrEntity.getAttr(), PaymentSheetEnum.BELONG_ID.getAttr()) || Objects.equals(fieldAttrEntity.getAttr(), PaySheetEnum.BELONG_ID.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    }
                }
                break;
            case INVOICE:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), InvoiceEnum.APPLY_USER.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                        break;
                    }
                }
                break;
            case PURCHASE_INVOICE:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), PurchaseInvoiceEnum.APPLY_USER.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                        break;
                    }
                }
                break;
            case PRODUCT:
            case SERVICE_PROJECT:
                map.put(RangeScreenConstant.VISIABLE_RANGE, I18nMessageUtil.getMessage(RangeScreenConstant.VISIABLE_NAME));
                break;
            case COMPETITOR:
                //可见人筛选
                map.put(RangeScreenConstant.VISIABLE_RANGE,I18nMessageUtil.getMessage(RangeScreenConstant.VISIABLE_NAME));
                break;
            case WORK_ORDER:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), WorkOrderEnum.OWNER_ID.getAttr()) && !Objects.equals(screenListPojo.getSubBusinessType(), XbbRefTypeEnum.WORK_ORDER_ROB.getCode())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    } else if (Objects.equals(fieldAttrEntity.getAttr(), WorkOrderEnum.COUSERID.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    } else if (Objects.equals(fieldAttrEntity.getAttr(), WorkOrderEnum.CREATOR_ID.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    }
                }
                break;
            case SYSTEM:
                map.put(FieldTypeEnum.OWNERID.getAlias(), I18nMessageUtil.getMessage(CommonConstant.MAIN_USER));
                map.put(FieldTypeEnum.OWNERID.getAlias(), "负责人");
                break;
            case CUSTOMER_COMMUNICATE:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), CustomerCommunicateEnum.CREATOR_ID.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    }
                }
                break;
            case SUPPLIER_COMMUNICATE:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), SupplierCommunicateEnum.CREATOR_ID.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), fieldAttrEntity.getAttrName());
                    }
                }
                break;
            case WORK_REPORT:
                for (FieldAttrEntity fieldAttrEntity : explainList) {
                    if (Objects.equals(fieldAttrEntity.getAttr(), WorkReportFieldEnum.CREATOR_ID.getAttr())) {
                        map.put(fieldAttrEntity.getAttr(), I18nMessageUtil.getMessage(CommonConstant.SUBMITTER));
                    }
                }
                break;
            case STOCK_FLOW_BILL:
                if (Objects.equals(screenListPojo.getPlatform(), PlatFormEnum.WEB.getValue())) {
                    SpecialListFieldPojo sheetDate = new SpecialListFieldPojo();
                    Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                    param.put("corpid", screenListPojo.getCorpid());
                    param.put("userId", screenListPojo.getUserId());
                    param.put("formId", screenListPojo.getFormId());
                    param.put("businessType", screenListPojo.getBusinessType());
                    param.put("del", DelEnum.NORMAL.getDel());
                    List<StockDateFilterEntity> stockDateFilterEntityList = stockDateFilterModel.findEntitys(param);
                    if (stockDateFilterEntityList.isEmpty()) {
                        JSONObject filterContent = new JSONObject();
                        filterContent.put("timeType", TimeTypeEnum.DAY.getCode());
                        filterContent.put("timeName", TimeTypeEnum.DAY.getName());
                        filterContent.put("maxYear", 1);
                        sheetDate.setFilterContent(filterContent);
                    } else {
                        sheetDate.setFilterContent(stockDateFilterEntityList.get(0).getContentData());
                        sheetDate.getFilterContent().put("maxYear", 1);
                    }
                    sheetDate.setAttr(FieldTypeEnum.STOCK_FLOW_SHEET_DATE.getAlias());
                    sheetDate.setAttrName(FieldTypeEnum.STOCK_FLOW_SHEET_DATE.getDescription());
                    sheetDate.setFieldType(FieldTypeEnum.STOCK_FLOW_SHEET_DATE.getType());
                    specialListFieldPojos.add(sheetDate);
                }
                SpecialListFieldPojo sheetNo = new SpecialListFieldPojo();
                StockFilterTypeEnum.getMapByFieldType(FieldTypeEnum.REF_ID.getType(), map);
                List<ItemPoJo> itemPoJoList = gerItems(map);
                sheetNo.setItems(itemPoJoList);
                sheetNo.setAttr(FieldTypeEnum.REF_ID.getAlias());
                sheetNo.setAttrName(FieldTypeEnum.REF_ID.getDescription());
                sheetNo.setFieldType(FieldTypeEnum.REF_ID.getType());
                specialListFieldPojos.add(sheetNo);
                SpecialListFieldPojo businessId = new SpecialListFieldPojo();
                map.clear();
                StockFilterTypeEnum.getMapByFieldType(FieldTypeEnum.BUSINESS_ID.getType(), map);
                itemPoJoList = gerItems(map);
                businessId.setItems(itemPoJoList);
                businessId.setAttr(FieldTypeEnum.BUSINESS_ID.getAlias());
                businessId.setAttrName(FieldTypeEnum.BUSINESS_ID.getDescription());
                businessId.setFieldType(FieldTypeEnum.BUSINESS_ID.getType());
                specialListFieldPojos.add(businessId);
                screenListVO.setSpecialScreens(specialListFieldPojos);
                return;
            case MARKETING_ACTIVITY_MANAGEMENT:
            case PROMOTION_ACTIVITY_MANAGEMENT:
                if (Objects.equals(screenListPojo.getPlatform(), PlatFormEnum.WEB.getValue())) {
                    SpecialListFieldPojo sheetDate = new SpecialListFieldPojo();
                    JSONObject filterContent = new JSONObject();
                    filterContent.put("timeType", TimeTypeEnum.YEAR.getCode());
                    filterContent.put("timeName", TimeTypeEnum.YEAR.getName());
                    filterContent.put("maxYear", 1);
                    sheetDate.setFilterContent(filterContent);
                    sheetDate.getFilterContent().put("maxYear", 1);
                    sheetDate.setAttr(FieldTypeEnum.STOCK_FLOW_SHEET_DATE.getAlias());
                    sheetDate.setAttrName(PromotionActivityManagementEnum.ACTIVITY_TIME.getAttrName());
                    sheetDate.setFieldType(FieldTypeEnum.STOCK_FLOW_SHEET_DATE.getType());
                    specialListFieldPojos.add(sheetDate);
                    screenListVO.setSpecialScreens(specialListFieldPojos);
                }
                return;
            case STOCK_STANDING_BOOK:
                if (Objects.equals(screenListPojo.getPlatform(), PlatFormEnum.WEB.getValue())) {
                    SpecialListFieldPojo sheetDate = new SpecialListFieldPojo();
                    Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                    param.put("corpid", screenListPojo.getCorpid());
                    param.put("userId", screenListPojo.getUserId());
                    param.put("formId", screenListPojo.getFormId());
                    param.put("businessType", screenListPojo.getBusinessType());
                    param.put("del", DelEnum.NORMAL.getDel());
                    List<StockDateFilterEntity> stockDateFilterEntityList = stockDateFilterModel.findEntitys(param);
                    if (stockDateFilterEntityList.isEmpty()) {
                        JSONObject filterContent = new JSONObject();
                        filterContent.put("timeType", TimeTypeEnum.DAY.getCode());
                        filterContent.put("timeName", TimeTypeEnum.DAY.getName());
                        filterContent.put("maxYear", 1);
                        sheetDate.setFilterContent(filterContent);
                    } else {
                        sheetDate.setFilterContent(stockDateFilterEntityList.get(0).getContentData());
                        sheetDate.getFilterContent().put("maxYear", 1);
                    }
                    sheetDate.setAttr(FieldTypeEnum.STOCK_FLOW_SHEET_DATE.getAlias());
                    sheetDate.setAttrName(FieldTypeEnum.STOCK_FLOW_SHEET_DATE.getDescription());
                    sheetDate.setFieldType(FieldTypeEnum.STOCK_FLOW_SHEET_DATE.getType());
                    specialListFieldPojos.add(sheetDate);
                }
                screenListVO.setSpecialScreens(specialListFieldPojos);
                return;
            case BATCH_FLOW_BILL:
                if (Objects.equals(screenListPojo.getPlatform(), PlatFormEnum.WEB.getValue())) {
                    SpecialListFieldPojo sheetDate = new SpecialListFieldPojo();
                    Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                    param.put("corpid", screenListPojo.getCorpid());
                    param.put("userId", screenListPojo.getUserId());
                    param.put("formId", screenListPojo.getFormId());
                    param.put("businessType", screenListPojo.getBusinessType());
                    param.put("del", DelEnum.NORMAL.getDel());
                    List<StockDateFilterEntity> stockDateFilterEntityList = stockDateFilterModel.findEntitys(param);
                    if (stockDateFilterEntityList.isEmpty()) {
                        JSONObject filterContent = new JSONObject();
                        filterContent.put("timeType", TimeTypeEnum.DAY.getCode());
                        filterContent.put("timeName", TimeTypeEnum.DAY.getName());
                        filterContent.put("maxYear", 1);
                        sheetDate.setFilterContent(filterContent);
                    } else {
                        sheetDate.setFilterContent(stockDateFilterEntityList.get(0).getContentData());
                        sheetDate.getFilterContent().put("maxYear", 1);
                    }
                    sheetDate.setAttr(FieldTypeEnum.STOCK_FLOW_SHEET_DATE.getAlias());
                    sheetDate.setAttrName(FieldTypeEnum.STOCK_FLOW_SHEET_DATE.getDescription());
                    sheetDate.setFieldType(FieldTypeEnum.STOCK_FLOW_SHEET_DATE.getType());
                    specialListFieldPojos.add(sheetDate);
                }
                sheetNo = new SpecialListFieldPojo();
                StockFilterTypeEnum.getMapByFieldType(FieldTypeEnum.REF_ID.getType(), map);
                itemPoJoList = gerItems(map);
                sheetNo.setItems(itemPoJoList);
                sheetNo.setAttr(FieldTypeEnum.REF_ID.getAlias());
                sheetNo.setAttrName(FieldTypeEnum.REF_ID.getDescription());
                sheetNo.setFieldType(FieldTypeEnum.REF_ID.getType());
                specialListFieldPojos.add(sheetNo);
                businessId = new SpecialListFieldPojo();
                map.clear();
                StockFilterTypeEnum.getMapByFieldType(FieldTypeEnum.BUSINESS_ID.getType(), map);
                itemPoJoList = gerItems(map);
                businessId.setItems(itemPoJoList);
                businessId.setAttr(FieldTypeEnum.BUSINESS_ID.getAlias());
                businessId.setAttrName(FieldTypeEnum.BUSINESS_ID.getDescription());
                businessId.setFieldType(FieldTypeEnum.BUSINESS_ID.getType());
                specialListFieldPojos.add(businessId);
                screenListVO.setSpecialScreens(specialListFieldPojos);
                return;
            case CUSTOMER_STATEMENT:
                map.put(FieldTypeEnum.OWNERID.getAlias(), I18nMessageUtil.getMessage(CommonConstant.MAIN_USER));
                map.put(FieldTypeEnum.COUSERID.getAlias(), I18nMessageUtil.getMessage(CommonConstant.COLLABORATOR));
                break;
            case GUARANTEE_SEARCH:
                break;
            case KNOWLEDGE_BASE:
                break;
            default:
                return;
        }
        List<ItemPoJo> itemPoJoList = gerItems(map);
        rangeScreen.setAttr(RangeScreenConstant.RANGE_SCREEN);
        rangeScreen.setAttrName(FieldTypeEnum.RANGE_SCREEN.getDescription());
        rangeScreen.setFieldType(FieldTypeEnum.RANGE_SCREEN.getType());
        // 是否多选 0：否；1：是
        rangeScreen.setMultiple(0);
        rangeScreen.setPlaceholder(I18nMessageUtil.getMessage(RangeScreenConstant.SELECT));
        rangeScreen.setItems(itemPoJoList);
        specialListFieldPojos.add(rangeScreen);
        screenListVO.setSpecialScreens(specialListFieldPojos);
    }

    /**
     * 获取item集合
     *
     * @param itemMap item值
     * @autuor: long.rao
     * @date: 2020-02-26 14:00:00
     */
    private List<ItemPoJo> gerItems(Map<String, String> itemMap) {
        List<ItemPoJo> itemPoJoList = new ArrayList<>();

        for (Map.Entry<String, String> entity : itemMap.entrySet()){
            ItemPoJo itemPoJo = new ItemPoJo();
            itemPoJo.setText(entity.getValue());
            itemPoJo.setAttr(entity.getKey());
            itemPoJo.setChecked(false);
            itemPoJoList.add(itemPoJo);
        }
        return itemPoJoList;
    }

    private void formatAppFilter(ScreenListDTO screenListDTO, ScreenListVO screenListVO) throws XbbException{
        Integer businessType = screenListDTO.getBusinessType();
        Map<String, FieldAttrEntity> fieldAttrEntityMap = new HashMap<>();
        for (Object obj : screenListVO.getFormExplainList()) {
            FieldAttrEntity fieldAttrEntity = (FieldAttrEntity) obj;
            if (Objects.isNull(fieldAttrEntity)) {
                continue;
            }
            boolean removeAttr = removeHandle(fieldAttrEntity, businessType);
            if (removeAttr) {
                continue;
            }
            fieldAttrEntityMap.put(fieldAttrEntity.getAttr(), fieldAttrEntity);
        }
        for (String attr : screenListVO.getScreen()) {
            FieldAttrEntity attrEntity = fieldAttrEntityMap.get(attr);
            if (Objects.isNull(attrEntity)) {
                continue;
            }
            // items处理开始
            if (Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.DATETIME.getType())
                    || Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.ADDTIME.getType())
                    || Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.UPDATETIME.getType())
                    || Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.ENDTIME.getType())
                    || Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.CLOSETIME.getType())) {
                // 处理日期
                attrEntity.setItems(searchFilterHelp.getTimeItemPoJos(attrEntity,attr));
                continue;
            }
            if (Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.OWNERID.getType())
                    || Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.COUSERID.getType())
                    || Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.CREATORID.getType())
                    || Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.USER.getType())
                    || Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.USER_GROUP.getType())
                    || Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.PRE_OWNER_ID.getType())) {
                // 负责人、协同人、创建人特殊处理,我的、下属的，选择成员 部门单选 部门多选
                attrEntity.setItems(formatUserItem());
                continue;
            }
            if(Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.DEPT.getType())
                    || Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.DEPT_GROUP.getType())
                    || Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.DEPARTMENTID.getType())){
                // 部门单选 部门多选 选择部门
                attrEntity.setItems(formatDeptItem());
                continue;
            }
            if (Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.COMBO.getType())
                    || Objects.equals(attrEntity.getFieldType(),FieldTypeEnum.COMBO_NUM.getType())
                    || Objects.equals(attrEntity.getFieldType(),FieldTypeEnum.BATCH.getType())
                    || Objects.equals(attrEntity.getFieldType(),FieldTypeEnum.SEQ.getType())
                    || Objects.equals(attrEntity.getFieldType(),FieldTypeEnum.COMBO_CHECK.getType())
                    || Objects.equals(attrEntity.getFieldType(),FieldTypeEnum.CHECKBOX_GROUP.getType())) {
                // 下拉框 逻辑下拉框
                attrEntity.setItems(formatCombo(attrEntity,screenListDTO));
                continue;
            }
            if (Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.STAR.getType())) {
                // 星级
                attrEntity.setItems(searchFilterHelp.getStarFilter(attrEntity));
                continue;
            }
            if (Objects.equals(attrEntity.getFieldType(),FieldTypeEnum.BIRTHDAY.getType())){
                // 生日
                attrEntity.setItems(searchFilterHelp.listOfBirthday());
                continue;
            }
            if (Objects.equals(attrEntity.getFieldType(),FieldTypeEnum.SWITCH.getType())){
                // 开关
                List<ItemPoJo> list = new ArrayList<>();
                list.add(new ItemPoJo(OperateTypeEnum.YES.getName(),1));
                list.add(new ItemPoJo(OperateTypeEnum.NO.getName(),0));
                attrEntity.setItems(list);
            }
            if (Objects.equals(attrEntity.getFieldType(),FieldTypeEnum.WORK_ORDER_NODE_STATUS.getType())){
                attrEntity.setItems(searchFilterHelp.listOfWorkOrderNodeStatus());
            }
            if (Objects.equals(attrEntity.getFieldType(),FieldTypeEnum.WORK_ORDER_STATUS.getType())){
                attrEntity.setItems(searchFilterHelp.listOfWorkOrderStatus(screenListDTO.getDefaultGroup(), screenListDTO.getListGroupId()));
            }
            if (Objects.equals(attrEntity.getFieldType(),FieldTypeEnum.WORK_ORDER_TIME_OUT.getType())){
                attrEntity.setItems(searchFilterHelp.listOfWorkOrderTimeOut());
            }

            if (Objects.equals(attrEntity.getFieldType(),FieldTypeEnum.WORK_ORDER_STAGE.getType())){
                attrEntity.setItems(searchFilterHelp.listOfWorkOrderStage(screenListDTO.getFormId(), screenListDTO.getCorpid()));
            }
            if (Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.LABEL.getType())){
                attrEntity.setItems(listofLabel(attrEntity,screenListDTO));
            }
            if (Objects.equals(attrEntity.getFieldType(), FieldTypeEnum.PUBLIC_GROUP.getType())){
                attrEntity.setItems(searchFilterHelp.getPublicGroupItems());
            }
            // 处理每个表单的特殊字段
            List<ItemPoJo> itemPoJos = formatSpecialItem(screenListDTO.getBusinessType(), attrEntity);
            if (CollectionsUtil.isNotEmpty(itemPoJos)) {
                attrEntity.setItems(itemPoJos);
            }
        }
        JSONArray explainArr = new JSONArray();
        explainArr.addAll(fieldAttrEntityMap.values());
        // 特殊业务增加归档状态
        // 处理每个表单的特殊字段
        if (!((Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.WAIT_OUTSTOCK.getCode()) || Objects.equals(screenListDTO.getSubBusinessType(), XbbRefTypeEnum.WAIT_PURCHASE.getCode())) && Objects.equals(screenListDTO.getPlatform(), PlatFormEnum.DINGTALK.getValue()))){
            FieldAttrEntity archivedAttr = formatArchivedItem(businessType, screenListDTO.getDistributorMark());
            if (Objects.nonNull(archivedAttr)) {
                explainArr.add(archivedAttr);
            }
        }
        // items处理结束
        if (Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.BATCH_FLOW_BILL.getCode()) && !fieldAttrEntityMap.containsKey(BatchFlowBillEnum.BUSINESS_ID.getAttr())) {
            FieldAttrEntity fieldAttrEntity = new FieldAttrEntity();
            fieldAttrEntity.setAttr(BatchFlowBillEnum.BUSINESS_ID.getAttr());
            fieldAttrEntity.setFieldType(FieldTypeEnum.BUSINESS_ID.getType());
            fieldAttrEntity.setAttrName(BatchFlowBillEnum.BUSINESS_ID.getAttrName());
            ItemPoJo customerItem = new ItemPoJo(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getName(), "customer");
            ItemPoJo supplierItem = new ItemPoJo(XbbRefTypeEnum.SUPPLIER.getName(), XbbRefTypeEnum.SUPPLIER.getAlias());
            List<ItemPoJo> itemPoJos = new ArrayList<>();
            itemPoJos.add(customerItem);
            itemPoJos.add(supplierItem);
            fieldAttrEntity.setItems(itemPoJos);
            explainArr.add(fieldAttrEntity);
        }
        if (Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.STOCK_FLOW_BILL.getCode()) && !fieldAttrEntityMap.containsKey(StockFlowBillEnum.BUSINESS_ID.getAttr())) {
            FieldAttrEntity fieldAttrEntity = new FieldAttrEntity();
            fieldAttrEntity.setAttr(StockFlowBillEnum.BUSINESS_ID.getAttr());
            fieldAttrEntity.setFieldType(FieldTypeEnum.BUSINESS_ID.getType());
            fieldAttrEntity.setAttrName(StockFlowBillEnum.BUSINESS_ID.getAttrName());
            ItemPoJo customerItem = new ItemPoJo(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getName(), "customer");
            ItemPoJo supplierItem = new ItemPoJo(XbbRefTypeEnum.SUPPLIER.getName(), XbbRefTypeEnum.SUPPLIER.getAlias());
            List<ItemPoJo> itemPoJos = new ArrayList<>();
            itemPoJos.add(customerItem);
            itemPoJos.add(supplierItem);
            fieldAttrEntity.setItems(itemPoJos);
            explainArr.add(fieldAttrEntity);
        }
        if (Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.PAYMENT.getCode()) && !fieldAttrEntityMap.containsKey(PaymentEnum.SOURCE.getAttr()) ) {
            FieldAttrEntity fieldAttrEntity = new FieldAttrEntity();
            fieldAttrEntity.setAttr(PaymentEnum.SOURCE.getAttr());
            fieldAttrEntity.setAttrName(PaymentEnum.SOURCE.getAttrName());
            fieldAttrEntity.setFieldType(FieldTypeEnum.SOURCE.getType());
            ItemPoJo paymentItem = new ItemPoJo(PaymentSourceTypeEnum.INVOICE.getName(), PaymentSourceTypeEnum.INVOICE.getAttr());
            ItemPoJo outstockItem = new ItemPoJo(PaymentSourceTypeEnum.OUTSTOCK.getName(), PaymentSourceTypeEnum.OUTSTOCK.getAttr());
            List<ItemPoJo> itemPoJos = new ArrayList<>();
            itemPoJos.add(paymentItem);
            itemPoJos.add(outstockItem);
            fieldAttrEntity.setItems(itemPoJos);
            explainArr.add(fieldAttrEntity);
        }
        if (Objects.equals(screenListDTO.getDistributorMark(), DistributorMarkEnum.DISTRIBUTOR.getCode()) && Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()) && fieldAttrEntityMap.containsKey(DistributorEnum.AREA.getAttr())) {
            FieldAttrEntity fieldAttrEntity = fieldAttrEntityMap.get(DistributorEnum.AREA.getAttr());
            ItemPoJo item = new ItemPoJo(I18nMessageUtil.getMessage(RangeScreenConstant.SELECT), I18nMessageUtil.getMessage(RangeScreenConstant.SELECT));
            item.setFieldType(fieldAttrEntity.getFieldType());
            item.setIsOther(0);
            List<ItemPoJo> itemPoJos = new ArrayList<>();
            itemPoJos.add(item);
            fieldAttrEntity.setItems(itemPoJos);
        }
        if (Objects.equals(screenListDTO.getDistributorMark(), DistributorMarkEnum.DISTRIBUTOR.getCode()) && Objects.equals(screenListDTO.getBusinessType(), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()) && fieldAttrEntityMap.containsKey(DistributorEnum.PURCHASEABLE_GOODS.getAttr())) {
            FieldAttrEntity fieldAttrEntity = fieldAttrEntityMap.get(DistributorEnum.PURCHASEABLE_GOODS.getAttr());
            ItemPoJo item = new ItemPoJo(I18nMessageUtil.getMessage(RangeScreenConstant.SELECT), I18nMessageUtil.getMessage(RangeScreenConstant.SELECT));
            item.setFieldType(fieldAttrEntity.getFieldType());
            item.setIsOther(0);
            List<ItemPoJo> itemPoJos = new ArrayList<>();
            itemPoJos.add(item);
            fieldAttrEntity.setItems(itemPoJos);
        }
        screenListVO.setFormExplainList(explainArr);
    }

    private List<ItemPoJo> listofLabel(FieldAttrEntity attrEntity, ScreenListDTO screenListDTO) throws XbbException {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        // 获取下拉框的值
        SearchDataInConditionDTO searchDataInConditionDTO = new SearchDataInConditionDTO();
        BeanUtil.copyProperties(screenListDTO,searchDataInConditionDTO);
        searchDataInConditionDTO.setAttr(attrEntity.getAttr());
        searchDataInConditionDTO.setFieldType(attrEntity.getFieldType());
        SearchDataInConditionVO searchDataInConditionVO = proFormDataService.dataConditionList(searchDataInConditionDTO);
        List<ItemDataPoJo> items = searchDataInConditionVO.getItems();
        if (Objects.nonNull(items)){
            for (int i = 0; i < items.size(); i++) {
                ItemDataPoJo itemDataPoJo = items.get(i);
                ItemPoJo itemPoJo = new ItemPoJo();
                itemPoJo.setText(Objects.nonNull(itemDataPoJo.getText()) ? itemDataPoJo.getText().toString() : "");
                itemPoJo.setValue(itemDataPoJo.getValue());
                itemPoJo.setIsOther(itemDataPoJo.getIsOther());
                itemPoJos.add(itemPoJo);
            }
        }
        // 自定义快捷筛选
        List<ItemPoJo> retItemPoJos = itemPoJos;
        if (Objects.nonNull(itemPoJos) && itemPoJos.size() > 9){
            retItemPoJos = itemPoJos.subList(0, 8);
            List<Object> value8 = new ArrayList<>();
            retItemPoJos.add(new ItemPoJo(I18nMessageUtil.getMessage(I18nStringConstant.ADVANCED_MORE),value8,attrEntity.getAttr() ,FieldTypeEnum.COMBO.getType()));
        }
        return retItemPoJos;
    }

    /**
     * 去除不要的字段
     * @param fieldAttrEntity
     * @param businessType
     * @return
     */
    private boolean removeHandle(FieldAttrEntity fieldAttrEntity, Integer businessType) {
        boolean removeFlag = false;
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        switch (xbbRefTypeEnum) {
            case STOCK_FLOW_BILL:
                if (Objects.equals(fieldAttrEntity.getAttr(), StockFlowBillEnum.NAME.getAttr())) {
                    removeFlag = true;
                }
                break;
            case STOCK_STANDING_BOOK:
                if (Objects.equals(fieldAttrEntity.getAttr(), StockStandingBookEnum.NAME.getAttr())) {
                    removeFlag = true;
                }
                break;
            case CUSTOMER_COMMUNICATE:
                if(Objects.equals(fieldAttrEntity.getAttr(),CustomerCommunicateEnum.VIDEO.getAttr()) || Objects.equals(fieldAttrEntity.getAttr(),CustomerCommunicateEnum.COMMUNICATE_BUSINESS.getAttr())) {
                    removeFlag = true;
                }
                break;
            default:
                break;
        }
        return removeFlag;
    }

    /**
     * 选择部门
     * @return
     */
    private List<ItemPoJo> formatDeptItem() {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo itemPoJo = new ItemPoJo();
        itemPoJo.setText(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_DEPARTMENT));
        itemPoJo.setFieldType(FieldTypeEnum.DEPARTMENTID.getType());
        itemPoJo.setValue(I18nMessageUtil.getMessage(I18nStringConstant.SELECT_DEPARTMENT));
        itemPoJos.add(itemPoJo);
        return itemPoJos;
    }

    /**
     * 处理下拉框类型
     * @return
     */
    private List<ItemPoJo> formatCombo(FieldAttrEntity fieldAttrEntity,ScreenListDTO screenListDTO) throws XbbException{
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        // 获取下拉框的值
        SearchDataInConditionDTO searchDataInConditionDTO = new SearchDataInConditionDTO();
        BeanUtil.copyProperties(screenListDTO,searchDataInConditionDTO);
        searchDataInConditionDTO.setAttr(fieldAttrEntity.getAttr());
        searchDataInConditionDTO.setFieldType(fieldAttrEntity.getFieldType());
        SearchDataInConditionVO searchDataInConditionVO = proFormDataService.dataConditionList(searchDataInConditionDTO);
        List<ItemDataPoJo> items = searchDataInConditionVO.getItems();
        if (Objects.nonNull(items)){
            for (int i = 0; i < items.size(); i++) {
                ItemDataPoJo itemDataPoJo = items.get(i);
                ItemPoJo itemPoJo = new ItemPoJo();
                itemPoJo.setText(Objects.nonNull(itemDataPoJo.getText()) ? itemDataPoJo.getText().toString() : "");
                itemPoJo.setValue(itemDataPoJo.getValue());
                itemPoJo.setIsOther(itemDataPoJo.getIsOther());
                itemPoJos.add(itemPoJo);
            }
        }
        // 自定义快捷筛选
        List<ItemPoJo> retItemPoJos = itemPoJos;
        if (Objects.nonNull(itemPoJos) && itemPoJos.size() > 9){
            retItemPoJos = itemPoJos.subList(0, 8);
            List<Object> value8 = new ArrayList<>();
            retItemPoJos.add(new ItemPoJo(I18nMessageUtil.getMessage(I18nStringConstant.ADVANCED_MORE),value8,fieldAttrEntity.getAttr() ,FieldTypeEnum.COMBO.getType()));
        }
        return retItemPoJos;
    }

    private List<ItemPoJo> formatSpecialItem(Integer businesType, FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businesType);
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
                if(Objects.equals(fieldAttrEntity.getAttr(),CustomerManagementEnum.BIRTHDAY.getAttr())){
                    itemPoJos.add(new ItemPoJo(BirthdayFilterEnum.TODAY.getText(),BirthdayFilterEnum.TODAY.getValue()));
                    itemPoJos.add(new ItemPoJo(BirthdayFilterEnum.TOMORROW.getText(),BirthdayFilterEnum.TOMORROW.getValue()));
                    itemPoJos.add(new ItemPoJo(BirthdayFilterEnum.SEVEN_DAYS.getText(),BirthdayFilterEnum.SEVEN_DAYS.getValue()));
                    return itemPoJos;
                }
                break;
            case SUPPLIER:

                break;
            case SUPPLIER_CONTACT:

                break;
            case SUPPLIER_COMMUNICATE:

                break;
            case PURCHASE:

                break;
            case RETURNED_PURCHASE:

                break;
            case BOM_BILL:

                break;
            case ASSEMBLE:

                break;
            case INVENTORY:

                break;
            case TRANSFER:

                break;
//            case PRODUCTION_ORDER:
//                if (Objects.equals(attr,SupplierEnum.ADD_TIME.getAttr())){
//                    itemPoJos = searchFilterHelp.getTimeItemPoJos(fieldAttrEntity,"addTime");
//                } else if ( Objects.equals(attr,SupplierEnum.UPDATE_TIME.getAttr())){
//                    itemPoJos = searchFilterHelp.getTimeItemPoJos(fieldAttrEntity,"updateTime");
//                } else if (Objects.equals(attr,SupplierEnum.LAST_CONNECT_TIME.getAttr())){
//                    itemPoJos = searchFilterHelp.getTimeItemPoJos(fieldAttrEntity,"date_2");
//                }
            case PURCHASE_INSTOCK:

                break;
            case REFUND_INSTOCK:

                break;
            case OTHER_INSTOCK:

                break;
            case PRODUCTION_INSTOCK:

                break;
            case RETURNED_MATERIEL_INSTOCK:

                break;
            case CONTRACT_OUTSTOCK:

                break;
            case RETURNED_PURCHASE_OUTSTOCK:

                break;
            case OTHER_OUTSTOCK:

                break;
            case PRODUCTION_MATERIEL_OUTSTOCK:

                break;
            case WORK_ORDER_OUTSTOCK:

                break;
            case WAREHOUSE:

                break;
            case PRODUCTION_ORDER:

                break;
            default:
                break;
        }
        return itemPoJos;
    }

    /**
     * 封装人员选项
     *
     * @throws
     * @author long.rao
     * @date 2020-07-30 11:05
     */
    private List<ItemPoJo> formatUserItem() {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        ItemPoJo myItem = new ItemPoJo();
        myItem.setText(RangeScreenTypeEnum.ME.getMemo());
        myItem.setValue(Arrays.asList(RangeScreenTypeEnum.ME.getType()));
        myItem.setFieldType(FieldTypeEnum.SELECT_DEPARTMENT.getType());
        myItem.setAlias("me");
        itemPoJos.add(myItem);

        ItemPoJo subItem = new ItemPoJo();
        subItem.setText(RangeScreenTypeEnum.MY_SUB.getMemo());
        subItem.setValue(Arrays.asList(RangeScreenTypeEnum.MY_SUB.getType()));
        subItem.setFieldType(FieldTypeEnum.SELECT_DEPARTMENT.getType());
        subItem.setAlias("mySub");
        itemPoJos.add(subItem);

        ItemPoJo selectItem = new ItemPoJo();
        selectItem.setText(RangeScreenTypeEnum.STAFF.getMemo());
        selectItem.setValue(Arrays.asList(RangeScreenTypeEnum.STAFF.getType()));
        selectItem.setFieldType(FieldTypeEnum.SELECT_DEPARTMENT.getType());
        selectItem.setAlias("ownerId");
        itemPoJos.add(selectItem);
        return itemPoJos;
    }

    private FieldAttrEntity formatArchivedItem(Integer businesType, Integer distributorMark) {
        List<ItemPoJo> itemPoJos = new ArrayList<>();
        FieldAttrEntity fieldAttrEntity = null;
        businesType = XbbRefTypeEnum.transferBusinessType4Distributor(businesType, distributorMark);
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businesType);
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
                fieldAttrEntity = new FieldAttrEntity();
                fieldAttrEntity.setAttr(CustomerManagementEnum.IS_ARCHIVED.getAttr());
                fieldAttrEntity.setFieldType(CustomerManagementEnum.IS_ARCHIVED.getFieldType());
                fieldAttrEntity.setAttrName(I18nMessageUtil.getMessage(StringConstant.ARCHIVED_STATUS));
                itemPoJos.add(new ItemPoJo(ArchivedEnum.UN_ARCHIVED.getName(), ArchivedEnum.UN_ARCHIVED.getCode()));
                itemPoJos.add(new ItemPoJo(ArchivedEnum.ARCHIVED.getName(), ArchivedEnum.ARCHIVED.getCode()));
                fieldAttrEntity.setItems(itemPoJos);
                break;
            case CONTRACT:
                fieldAttrEntity = new FieldAttrEntity();
                fieldAttrEntity.setAttr(ContractEnum.ARCHIVED.getAttr());
                fieldAttrEntity.setFieldType(ContractEnum.ARCHIVED.getFieldType());
                fieldAttrEntity.setAttrName(I18nMessageUtil.getMessage(StringConstant.ARCHIVED_STATUS));
                itemPoJos.add(new ItemPoJo(ArchivedEnum.UN_ARCHIVED.getName(), ArchivedEnum.UN_ARCHIVED.getCode()));
                itemPoJos.add(new ItemPoJo(ArchivedEnum.ARCHIVED.getName(), ArchivedEnum.ARCHIVED.getCode()));
                fieldAttrEntity.setItems(itemPoJos);
                break;
            case SALES_OPPORTUNITY:
                fieldAttrEntity = new FieldAttrEntity();
                fieldAttrEntity.setAttr(SalesOpportunityEnum.IS_ARCHIVED.getAttr());
                fieldAttrEntity.setFieldType(SalesOpportunityEnum.IS_ARCHIVED.getFieldType());
                fieldAttrEntity.setAttrName(I18nMessageUtil.getMessage(StringConstant.ARCHIVED_STATUS));
                itemPoJos.add(new ItemPoJo(ArchivedEnum.UN_ARCHIVED.getName(), ArchivedEnum.UN_ARCHIVED.getCode()));
                itemPoJos.add(new ItemPoJo(ArchivedEnum.ARCHIVED.getName(), ArchivedEnum.ARCHIVED.getCode()));
                fieldAttrEntity.setItems(itemPoJos);
                break;
            case QUOTATION:
                fieldAttrEntity = new FieldAttrEntity();
                fieldAttrEntity.setAttr(QuotationEnum.ARCHIVED.getAttr());
                fieldAttrEntity.setFieldType(QuotationEnum.ARCHIVED.getFieldType());
                fieldAttrEntity.setAttrName(I18nMessageUtil.getMessage(StringConstant.ARCHIVED_STATUS));
                itemPoJos.add(new ItemPoJo(ArchivedEnum.UN_ARCHIVED.getName(), ArchivedEnum.UN_ARCHIVED.getCode()));
                itemPoJos.add(new ItemPoJo(ArchivedEnum.ARCHIVED.getName(), ArchivedEnum.ARCHIVED.getCode()));
                fieldAttrEntity.setItems(itemPoJos);
                break;
            default:
                break;
        }
        return fieldAttrEntity;
    }
}
